我有一个UITableViewCell
与它链接的类的自定义。
在awakeFromNib
(自定义单元格类的)中,我做了一个for in
循环:
for (id view in self.subview)
{
if (view isKindOfClass:[UITextField class]) {
UITextField *textField = (UITextField *)view;
[textField setBackgroundColor:[UIColor redColor]];
}
}
当我在模拟器上运行它时,textFields
背景颜色没有变化。
我敢肯定,我的错是:self.subview
。我该怎么代替呢?
从self.contentView获取子视图-
试试下面的代码
for (id view in self.contentView.subviews) {
if ([view isKindOfClass:[UITextField class]]) {
UITextField *textField = (UITextField *)view;
[textField setBackgroundColor:[UIColor redColor]];
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句