Reputation: 9660
This is kind of strange issue! I am using the UIAppearance API to style my UITableViewCells. I use the following code to style the UITableViewCell.
// table cell
id tableCellAppearance = [UITableViewCell appearance];
[tableCellAppearance setBackgroundView:[theme imageViewForTableViewCellBackground]];
// table cell
-(UIImageView *) imageViewForTableViewCellBackground
{
UIImageView *backgroundView = [[UIImageView alloc] init];
[backgroundView setImage:[UIImage imageNamed:@"tile_heading_background"]];
return backgroundView;
}
When I run the app and see the UITableViewCells only 1 cell is styled in the UITableView. The cell in the middle. Why is that?
Upvotes: 1
Views: 616
Reputation: 12671
Create a CustomUITableViewCell
and implement the <UIAppearance>
Protocol
CustomCell.h
@interface CustomCell : UITableViewCell <UIAppearance>
@property (nonatomic, weak) UIColor *backgroundCellColor UI_APPEARANCE_SELECTOR;
CustomCell.m
@implementation CustomCell
@synthesize backgroundCellColor;
-(void)setBackgroundCellColor:(UIColor *)backgroundColor
{
[super setBackgroundColor:backgroundColor];
}
Finally use the CustomCell in your view and set background or image
[[CustomCell appearance] setBackgroundCellColor:[UIColor redColor]];
Upvotes: 2