1.设置tableView的背景
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg"]];
self.tableView.backgroundView = nil;
2.iOS6.7的cell适配
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self setupBackground];
[self clearSubView];
[self addDivider];
}
return self;
}
- (void)addDivider
{
if (!iOS7) {
UIView *divider = [[UIView alloc] init];
divider.backgroundColor = [UIColor blackColor];
[self.contentView addSubview:divider];
divider.alpha = 0.4;
self.divider = divider;
}
}
- (void)clearSubView
{
self.textLabel.backgroundColor = [UIColor clearColor];
self.detailTextLabel.backgroundColor = [UIColor clearColor];
}
- (void)setupBackground
{
UIView *selView = [[UIView alloc] init];
selView.backgroundColor = NJColor(232, 228, 209);
self.selectedBackgroundView = selView;
UIView *norView = [[UIView alloc] init];
norView.backgroundColor = [UIColor whiteColor];
self.backgroundView = norView;
}
- (void)setFrame:(CGRect)frame
{
if (!iOS7) {
frame.size.width += 20;
frame.origin.x -= 10;
}
[super setFrame:frame];
}
- (void)layoutSubviews
{
[super layoutSubviews];
CGFloat dividerX = 0;
CGFloat dividerW = [UIScreen mainScreen].bounds.size.width;
CGFloat dividerH = 1;
CGFloat dividerY = self.contentView.frame.size.height - dividerH;
self.divider.frame = CGRectMake(dividerX, dividerY, dividerW, dividerH);
}