首页 > 其他 > 详细

自定义UITableView的Seperator

时间:2015-12-21 17:53:20      阅读:170      评论:0      收藏:0      [点我收藏+]

在默认配置中 ,UITableView的Cell之间的Seperator左边总是空出一块,即使在Storyboard中设置为0 ,也没有效果

需要在代码中进行配置,在ViewController中实现如下方法

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

    // Remove seperator inset

    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {

        [cell setSeparatorInset:UIEdgeInsetsZero];

    }

    

    // Prevent the cell from inheriting the Table View‘s margin settings

    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {

        [cell setPreservesSuperviewLayoutMargins:NO];

    }

    

    // Explictly set your cell‘s layout margins

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {

        [cell setLayoutMargins:UIEdgeInsetsZero];

    }

}

如果所有的界面都是如此风格,也可以通过UIAppearance 统一配置

// iOS 7:

[[UITableView appearance] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];

[[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];

 

[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];

 

// iOS 8:

if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {

    [[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];

    [[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];

    [[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO]; 

}

原文链接:http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working

自定义UITableView的Seperator

原文:http://www.cnblogs.com/taojigu/p/5063736.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!