解决部分cell设置AccessoryType,子视图适配问题,主要原因的contentView的宽度(width)大小的改变
如图,对勾imageView对不齐问题
1.创建自定义cell
1.自定义的Cell包含一个label和imageView
- label和imageView居中对齐
- label.Leading = 15 (距左15)
- imageView.CenterX = SuperView.Trailing * 0.9
2.设置AccessoryType
奇数行设置为UITableViewCellAccessoryDisclosureIndicator
偶数行设置为UITableViewCellAccessoryNone
2.设置AccessoryView
奇数行设置AccessoryType,偶数行设置AccessoryView
if (indexPath.row & 1) {
self.accessoryView = nil;
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}else {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 18, 40)];
self.accessoryView = view;
}
- 1.设置AccessoryView后AccessoryType将不起作用
因为Cell重用,所以设置AccessoryType之前需要将AccessoryView设置为nil- 2.不同类型的accessoryType对应的view的宽度不同UITableViewCellAccessoryDisclosureIndicator -> view.width = 18
UITableViewCellAccessoryDetailDisclosureButton -> view.width = 52
UITableViewCellAccessoryCheckmark -> view.width = 24
UITableViewCellAccessoryDetailButton -> view.width = 32