1 如何取消系統(tǒng)分割線的左邊間隙
// 在tableView中取消分割線內(nèi)邊距
self.tableView.separatorInset = UIEdgeInsetsZero;
// 在cell中,取消layoutMargins
// 從xib加載就會調(diào)用 只會調(diào)用一次
- (void)awakeFromNib {
[super awakeFromNib];
self.layoutMargins = UIEdgeInsetsZero;
}
2 重寫frame的set方法
1.取消系統(tǒng)的分割線,設置tableView背景色為分割線顏色
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.backgroundColor = [UIColor grayColor];
2.重寫frame的set方法
// 返回每個cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
// 返回每個cell樣式
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath ;
基于 tableView的代理方法中,先計算好cell的高度,再給cell賦值,故可以在賦值之前重寫setFrame方法,留出間隙
# 設置cell的frame
- (void)setFrame:(CGRect)frame
{
frame.size.height -= 1;
// 真正給cell設置frame
[super setFrame:frame];
}
備注:通過這個方法可以設置cell四周的間隙
3 在xib中畫分割線
1.取消系統(tǒng)的分割線
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
2.在xib同添加view并設置顏色,手動添加分割線
最后編輯于 :
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者