ios7 ios8 cell中下划线偏移(separator Insets)处理方法
2015-05-29 14:02
459 查看
在ios7中,UITableViewCell左侧会有默认15像素的空白。这时候,设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉。 但是在ios8中,设置setSeparatorInset:UIEdgeInsetsZero 已经不起作用了。下面是解决办法 首先在viewDidLoad方法加入以下代码: if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在UITableView的代理方法中加入以下代码 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
以上内容来自:http://www.bugfly.cn/?id=35
但是以上内容某些情况下还是有问题 可以参考这个以下这个处理:
在xib中对tableview的separator insets做设置,custom类型left,right都赋值成0,但实际显示的时候会发现左边还是有15px的边距。
问题解决帖:
http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working
文中描述了多种解决方式,我只尝试了一种,已经解决了该问题。
即对子类化的自定义cell类,覆盖layoutMargins属性的getter方法。
- (UIEdgeInsets)layoutMargins
{
return UIEdgeInsetsZero;
}
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在UITableView的代理方法中加入以下代码 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
以上内容来自:http://www.bugfly.cn/?id=35
但是以上内容某些情况下还是有问题 可以参考这个以下这个处理:
在xib中对tableview的separator insets做设置,custom类型left,right都赋值成0,但实际显示的时候会发现左边还是有15px的边距。
问题解决帖:
http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working
文中描述了多种解决方式,我只尝试了一种,已经解决了该问题。
即对子类化的自定义cell类,覆盖layoutMargins属性的getter方法。
- (UIEdgeInsets)layoutMargins
{
return UIEdgeInsetsZero;
}
相关文章推荐
- ios7 tableview scrollsToTop 不执行处理方法
- ios7 indexPathForCell 的坑(真是一个大大的坑)
- IOS开发中的几种设计模式介绍
- FFmpeg在iOS上完美编译
- iOS webView中调用JS与JS注入
- iOS7 edgesForExtendedLayout
- Toncat-OpenSSL双向认证配置(iOS)
- xcode 运行错误总结
- iOS开发的22个奇谲巧技
- 仿制新浪微博iOS客户端之一-序言
- IOS开发入门初体验
- 数据存储:数据持久化
- 数据存储:获取文件目录
- ios8之后的CLLOCATION定位权限申请
- iOS:Compile error List(二)--Special
- 用CocoaPods做iOS程序的依赖管理
- 网易新闻iOS版使用的18个开源组件
- iOS手势
- iOS中keychain存储结构的研究
- IOS开发中tableView显示列表内容数据(storyboard版)