//调整边距
Swift : UIEdgeInsetsZero 为全屏显示
//cell 扩展
extension UITableViewCell{
/** 让cell分割线满屏*/
func onSeparatorInsetZero(){
self.layoutMargins = UIEdgeInsets.zero
self.separatorInset = UIEdgeInsets.zero
}
//隐藏分割线
func onSeparatorNone(){
self.layoutMargins = UIEdgeInsets(top: 0, left: kScreen_width, bottom: 0, right: 0)
self.separatorInset = UIEdgeInsets(top: 0, left: kScreen_width, bottom: 0, right: 0)
}
}
UIEdgeInsetsMake(0, kScreenWidth, 0, 0) 这个是隐藏某一行
-(void)setLastCellSeperatorToLeft:(UITableViewCell*)cell
{
if([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsMake(0, kScreenWidth, 0, 0)];
//UIEdgeInsetsZero
}
if([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsMake(0, kScreenWidth, 0, 0)];
}
if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){
[cell setPreservesSuperviewLayoutMargins:NO];
}
}
//调用
-(UITableViewCell* )tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
YMMeCell* cell = [YMMeCell shareCell];
cell.titlLabel.text = self.titlesArr[indexPath.section][indexPath.row];
cell.iconImgView.image = [UIImage imageNamed:self.iconsArr[indexPath.section][indexPath.row]];
//最后一行分割线顶头显示
NSArray* sectTitlArr = self.titlesArr[indexPath.section];
if(indexPath.row == sectTitlArr.count-1) {
[self setLastCellSeperatorToLeft:cell] ;
}
return cell;
}
//或者在自定义cell里面,在awakeFromNib 添加代码
- (void)awakeFromNib {
[super awakeFromNib];
[self setSeparatorInset:UIEdgeInsetsMake(0, kScreenWidth, 0, 0)];
[self setLayoutMargins:UIEdgeInsetsMake(0, kScreenWidth, 0, 0)];
}
网友评论