2014-09-25 83 views
0

我有以下的代码来创建一个单元格背景图作为一个圆角矩形:动态更改单元格的backgroundView.backgroundColor

- (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

,你必须去了解它的方式是:

[cell setBackgroundView:[self createBackgroundView]]; 

也许你还应该添加一个参数传递给方法:

- (UIView *)createBackgroundView:(UIColor *)color; 
相关问题