UITableViewCell的常见设置
- 分割线颜色
- 分割线颜色,系统自带的分割线两边是不到屏幕边缘,当边缘有图片时更加明显,达不到所要的要求
- 解决:可以将系统的分割线隐藏,自定义一个view,位置紧贴cell底部,设置为亮灰色,高度为1,如果太粗可以设置提高透明度
//self.tableView.separatorColor = [UIColor redColor]
// 隐藏分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone
- 常用几个属性
- selectionStyle:选中样式(颜色),系统只有灰色和无,要想使用其他颜色或者显示图片等效果可以通过cell.selectedBackgroundView属性设置.
- selectedBackgroundView:设置选中后的背景效果,以为内继承自view,可以设置颜色,图片,其他控件等
- backgroundColor:默认背景色
- backgroundView:设置背景效果,继承自view,可以自定义颜色,图片等.
等级比 backgroundColor
高,比如分别通过backgroundView和backgroundColor设置背景色,只会显示backgroundView设置的背景色.
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *selectedBackgroundView = [[UIView alloc] init];
selectedBackgroundView.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = selectedBackgroundView;
cell.backgroundColor = [UIColor blueColor];
UIView *backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = [UIColor greenColor];
cell.backgroundView = backgroundView;
- 设置指示器
- accessoryType:位置在cell的右侧
- UITableViewCellAccessoryDisclosureIndicator
- UITableViewCellAccessoryDetailDisclosureButton
- UITableViewCellAccessoryCheckmark
- UITableViewCellAccessoryDetailButton
- UITableViewCellAccessoryNone
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;