[英]Right and left margin to UITableViewCell
I created the following UITableViewCells and set the background to white. 我创建了以下UITableViewCells并将背景设置为白色。
(the black frame is the simulator frame). (黑框是模拟器框)。
I would like to add margins right and left to the cell. 我想向单元格左右添加边距。
I looked in many Q&A and they all suggested customizing the cell with UiImageView. 我查看了许多问答,他们都建议使用UiImageView定制单元。 Is there another way to do it?
还有另一种方法吗?
add UIView
as contentView of the cell: 将
UIView
添加为单元格的contentView:
in cellForRowAtIndexPath
在
cellForRowAtIndexPath
UIView *viewLeft = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, heightOfTheCell)];
viewLeft.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:viewLeft];
UIView *viewRight = [[UIView alloc] initWithFrame:CGRectMake(310, 0, 10, heightOfTheCell)];
viewRight.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:viewRight];
and in this way you can have round corners: 这样,您就可以拥有圆角:
[cell.layer setCornerRadius: 5];
[cell.layer setMasksToBounds:YES];
[cell.layer setBorderWidth:2.0f]
CGColorRef colorRed = [[UIColor redColor] CGColor];
[cell.layer setBorderColor:colorRed];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.