为UITableViewCell中的UITextField设置backgroundColor
问题描述:
如何以编程方式更改位于UITableViewCell中的UITextField的backgroundColor?为UITableViewCell中的UITextField设置backgroundColor
设置UITextField.backgroundColor似乎不起作用。
答
我有同样的问题。我通过创建自己的UITextField并将其添加到UITableViewCell来解决它,但我不知道是否有更好的方法来完成它。
答
试试在layoutSubviews方法中使用这个单元格。
- (void)layoutSubviews {
[super layoutSubviews];
self.textLabel.backgroundColor = [UIColor blackColor];
}
+0
相同的效果,textField未填充(即使框架区域(特别是角落)显示颜色 – iFloh 2010-04-26 10:46:03
创建了自己的?你重写了什么? – iFloh 2010-04-26 10:24:55
你只需要将子视图添加到单元格contentView中,如下所示: [cell.contentView addSubview:yourTextView]; yourTextView是一个UILabel,您初始化,设置其CGRect,设置其文本,并设置其backgroundColor – Sorig 2010-04-26 16:06:56