我是新來的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) –