我是新来的iOS,我有一个分组表格视图,一节如下。我如何设置单元格的左右边距?如何为表格单元部分添加左右边距?
这里是我的边界设置代码...
[cell.layer setBorderColor:[UIColor colorWithRed:0.00 green:0.60 blue:1.00 alpha:1.0].CGColor];
[cell.layer setBorderWidth:1.0f];
[cell.layer setCornerRadius:5];
我是新来的iOS,我有一个分组表格视图,一节如下。我如何设置单元格的左右边距?如何为表格单元部分添加左右边距?
这里是我的边界设置代码...
[cell.layer setBorderColor:[UIColor colorWithRed:0.00 green:0.60 blue:1.00 alpha:1.0].CGColor];
[cell.layer setBorderWidth:1.0f];
[cell.layer setCornerRadius:5];
不喜欢
步骤-1
创建一个通用UIView
命名为BackgroundView
。而设定子视图cell.contentView
步骤-2
设置在框架上BackgroundView
任何你所需要的。基于内容查看宽度
步骤-3
添加Label
,Date
,Image
到子视图的BackgroundView
。
步骤-4
然后设置图层为BackgroundView
,最终的答案,你会得到
[cell.BackgroundView setBorderColor:[UIColor colorWithRed:0.00 green:0.60 blue:1.00 alpha:1.0].CGColor];
[cell.BackgroundView setBorderWidth:1.0f];
[cell.BackgroundView setCornerRadius:5];
最好的编程实践,这是继承您的UITableViewCell并覆盖其SETFRAME方法。
- (void)setFrame:(CGRect)frame {
frame.origin.x += 10;
frame.size.width -= 20;
[super setFrame:frame];
}
此外,您还可以设置单元格的圆角半径和颜色的drawRect方法
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
// border radius
[self.layer setCornerRadius:5.0f];
// border
[self.layer setBorderColor:[UIColor colorWithRed:0.00 green:0.60 blue:1.00 alpha:1.0].CGColor];
[self.layer setBorderWidth:1.0f];
}
还有一件事,如果你只是想使细胞多了几分吸引力
[self.layer setShadowColor:[UIColor lightGrayColor].CGColor];
[self.layer setShadowOpacity:0.8];
[self.layer setShadowRadius:3.0];
[self.layer setShadowOffset:CGSizeMake(2.0, 2.0)];
:在
的drawRect太添加此方法
self.tableView.contentInset = UIEdgeInsetsMake(0,20,0,20) –