将tableview的cell宽度变窄

最近公司新开了一个项目,有点小忙.准备忙里偷闲将项目过程中遇到的和之前遗忘的问题总结一下,方便学习和以后查阅.

  • 需求

需要将cell的宽度短于tableview的宽度,左右留下间距,美观;如图

  • 解决

自定义cell,继承UITableViewCell,重写cell的setframe方法

1
2
3
4
5
- (void)setFrame:(CGRect)frame {
frame.origin.x += inset;
frame.size.width -= 2 * inset;
[super setFrame:frame];
}

效果如图,完美解决

  • 参考资料

点我查看

这个人很帅<br>他什么都不想说<br>