简体   繁体   English

UITableViewCell的左右边距

[英]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.

相关问题 如何实现具有固定右边距和灵活左边距的UIView? - How to implement the UIView with fixed right margin and flexible left margin? UITableViewCell如何检测用户向左或向右滑动? - UITableViewCell How can I detect that the user has swiped left or Right? Objective-C UITableViewCell左/右/上/下空间 - Objective-C UITableViewCell left/right/top/bottom space 如何在UITableViewCell中使用UITextAlignment在Swift中左右对齐文本 - How to use UITextAlignment to align text in UITableViewCell to the right and left in Swift 检测已单击uitableviewcell的哪一侧:左或右 - Detect which side of uitableviewcell has been click: left or right UITableViewCell - 如何制作正确的UILabel截断而不是左边的截断? - UITableViewCell - how to make right UILabel truncate instead of left one? UITableViewCell背景颜色在单元格的左右边缘是不同的阴影 - UITableViewCell Background Color is a different shade at left and right edges of cell 如何减少/删除分组UITableView中的左/右边距? - how to reduce/remove the left/right hand margin in a grouped UITableView? 在iPhone iPhone 6 plus中,全角组件的左侧和右侧都有边距 - In iPhone iPhone 6 plus there is a margin on right and left side of full width components 自动在iPad / iPhone上设置左右边距自动宽度和900px宽度,并具有额外的边距 - Margin left/right auto and 900px width is positioning with extra wide margin on the iPad/iPhone only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM