美文网首页
修改Cell下划线长度

修改Cell下划线长度

作者: Miss_QL | 来源:发表于2018-02-26 14:36 被阅读27次

有时候项目中会有这样的需求,将Cell下划线长度设置为屏幕的宽,只需实现delegate协议中一个可选的方法- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath即可。

需要知道的是willDisplayCell是cell在tableview展示之前就会调用,此时cell实例已经生成,所以不能更改cell的结构,只能是改动cell上的一些UI属性。

// Cell下划线长度设置为屏幕的宽
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (SYSTEM_VERSION >= 7.0) {
        if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
            [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
        }
        if (SYSTEM_VERSION >= 8.0) {
            if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
                [cell setPreservesSuperviewLayoutMargins:NO];
            }
            if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
                [cell setLayoutMargins:UIEdgeInsetsZero];
            }
        }
    }
}

如果你有更好的方法的话,欢迎交流🙂

相关文章

网友评论

      本文标题:修改Cell下划线长度

      本文链接:https://www.haomeiwen.com/subject/fhryxftx.html