我有以下代码将单元格的背景视图创建为圆角矩形:
- (UIView *)createBackgroundView
{
CGRect background = CGRectMake(50, 25, self.frame.size.width - 60, 90);
UIView *backgroundView = [[UIView alloc] initWithFrame:background];
backgroundView.backgroundColor = [UIColor colorWithRed:0.78 green:0.96 blue:0.39 alpha:1];
[backgroundView.layer setCornerRadius:7.0f];
[backgroundView.layer setMasksToBounds:YES];
return backgroundView;
}
稍后在程序中我想更新backgroundView的backgroundColor,我试过
cell.backgroundView.backgroundColor = [UIColor redColor];
在cellForRowAtIndexPath和willDisplayCell中似乎都没有更新它。
答案 0 :(得分:0)
你必须要做的是:
[cell setBackgroundView:[self createBackgroundView]];
也许您还应该为方法添加一个参数:
- (UIView *)createBackgroundView:(UIColor *)color;