iOS边练边学--UITableViewCell的常见属性设置

时间:2023-03-09 06:33:52
iOS边练边学--UITableViewCell的常见属性设置
 // 取消选中的样式(常用) 让当前 cell 按下无反应
cell.selectionStyle = UITableViewCellSelectionStyleNone; // 设置选中的背景色,UIView无需设置UIView的尺寸
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; // backgroundView的优先级 > backgroundColor
// 设置指示器,系统默认的几个选项
// cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// 也可以自己设置指示器,这里讲指示器做成了开关
cell.accessoryView = [[UISwitch alloc] init];