how to change TTStyledTextTableItemCell 's background
Suppose I create TTTableStyledTextItem
objects in <TTTableViewDataSource>
conforming class as follows:
NSString* text = [NSString stringWithFormat:@"<b>%@</b>\n%@", @"aaaa..", @"bbbb.."];
TTStyledText* styledText = [TTStyledText textFromXHTML:text lineBreaks:YES URLs:NO];
TTTableStyledTextItem* item = [TTTableStyledTextItem itemWithText:styledText URL:@"my://url"];
By default, the table view cell class returned by tableView:cellClassForObject:
is going to be TTStyledTextTableItemCell
.
This works all right by I'd like to customize the background color of the cell when it 开发者_JS百科is in the normal state (when it is not in the selected state).
I've managed to change the cell's background in the selected state by creating a TTStyledTextTableItemCell
subclass and overriding the initWithStyle:reuseIdentifier:
initializer as follows:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)identifier {
self = [super initWithStyle:style reuseIdentifier:identifier];
if (self) {
// WORKS!
// cell's backgroundview (selected)
UIView *selectedView = [[UIView alloc] init];
selectedView.backgroundColor = [UIColor someColor..];
self.selectedBackgroundView = selectedView;
// DOESN'T WORK
// cell's background (normal)
UIView *normalView = [[UIView alloc] init];
normalView.backgroundColor = [UIColor someColor..];
self.backgroundView = normalView;
}
return self;
}
but I can't find a way to change the background of the cell when it's not selected (self.backgroundView
). I know that there's an associated TTStyledTextLabel
subview in the TTStyledTextTableItemCell
class, but I still have no success customizing it.
Is there an easy way to achieve this?? Thanks
精彩评论