1,tableview的背景颜色设置
tableview的分组样式,(plan样式没有)会有一个 backgroundView,会覆盖设置的背景颜色backgroundColor,所以要先清空这个backgroundView,代码如下: self.tableView.backgroundView = nil;
self.tableView.backgroundColor = [UIColorcolorWithPatternImage:[UIImageimageNamed:@"bg"]];
2,cell的背景设置
为了使iOS 6 中的cell,和iOS 7 里面的效果一样,像iOS 6 中的cell的圆角效果,被选中时的蓝色背景,自己创建view,并设置背景颜色,分别赋给self.backgroundView和self.selectedBackgroundView通过设置被选中cell的 selectedBackgroundView,来实现被选中时cell的颜色,因为这个只需要一次操作所以在初始化方法里面设置
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [superinitWithStyle:stylereuseIdentifier:reuseIdentifier]) {
// 初始化操作
// 设置选中时的背景
UIView *selectedBg = [[UIViewalloc]init];
selectedBg.backgroundColor = myColor(237,233,218);
self.selectedBackgroundView = selectedBg;
//设置普通时的背景
UIView *bg = [[UIViewalloc]init];
bg.backgroundColor = [UIColorwhiteColor];
self.backgroundView = bg;
}
returnself;
}
3,设置cell的之间的分割线
1,在初始化方法中,创建UIView设置背景色黑色和透明度,
2,在layerOutSubView中设置创建的frame,
3,判断是否是最后一行,若是则隐藏
4,设置IOS 6 的cell的宽度为屏幕宽度,没有间距
iOS 6 中cell的contentView的frame的x值为10,宽度为280,和cell的两边的间距为10,将cell的宽度加20,同时将x值设为-10;
思路:cell的frame,是在返回cell的dataSource方法中,被tableview设置的,默认为320,
在UITableCell中拦截这个设置frame的方法,即重写setFrame方法,
5,设置cell内部label和detailLabel的背景颜色为clearColor