iOS UITableViewCell的一些事

//可以去掉分割線
- (void)addSubview:(UIView *)view{
    if ([view isKindOfClass:NSClassFromString(@"_UITableViewCellSeparatorView")]) {
        return;
    }
    [super addSubview:view];
}
//改變cell的frame
- (void)setFrame:(CGRect)frame{
    /*
     左右距離 10 ,y+10,高度減少15
     */
    if (frame.size.height < 1) {//直接==0 在Xcode11下編譯有bug
        [super setFrame:frame];
        return;
    }
    frame.origin.x = 15;
    frame.size.width -= 2 * frame.origin.x;
//    frame.origin.y += 10;
    frame.size.height -= 20;
    [super setFrame:frame];
}
//取消點(diǎn)擊效果
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//簡單修改UITableViewHeaderFooterView的字體、顏色等
//新建個(gè)類繼承UITableViewHeaderFooterView,然后在layoutSubviews里修改
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.textLabel.font = [UIFont boldSystemFontOfSize:18];
    if (@available(iOS 13.0, *)) {
        self.textLabel.textColor = [UIColor labelColor];
    } else {
        self.textLabel.textColor = [UIColor blackColor];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   ...
    
    cell.preservesSuperviewLayoutMargins = NO;///>=iOS 8,子view和父view間有8個(gè)像素
    cell.layoutMargins = UIEdgeInsetsMake(0, 20, 0, 20);///>=iOS 8
    cell.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);///<=iOS 7,默認(rèn)距左15
    
    return cell;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容