解决iOS7,iOS8UITableView分割线距左边有距离的办法
2015-07-28 12:02
447 查看
解决UITableView分割线距左边有距离的办法,有需要的朋友可以参考下。
我们在使用tableview时会发现分割线的左边会短一些,通常可以使用setSeparatorInset:UIEdgeInsetsZero 来解决。但是升级到XCode6之后,在iOS8里发现没有效果。下面给出解决办法:
首先在viewDidLoad方法中加上如下代码:
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在willDisplayCell方法中加入如下代码:
- (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];
}
}
这样就可以正常显示了。
我们在使用tableview时会发现分割线的左边会短一些,通常可以使用setSeparatorInset:UIEdgeInsetsZero 来解决。但是升级到XCode6之后,在iOS8里发现没有效果。下面给出解决办法:
首先在viewDidLoad方法中加上如下代码:
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
然后在willDisplayCell方法中加入如下代码:
- (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];
}
}
这样就可以正常显示了。
相关文章推荐
- ios -UI-UI-菜单栏+导航栏
- UIImageView实现动画
- Quintus小游戏制作之Beta(二)
- 关于UITableView中的 TableFooterView的使用介绍
- JavaSE实战——GUI简述、用户登录注册最终版、模拟微信打飞机游戏实例
- HTML textarea的value 问题
- 在iOS8系统下,UITabbar上的item自定义背景色和图片问题
- 自己动手实现一个队列LGQueue(刚刚)
- android 推送 mosquitto MQTT
- UIView之动画效果的实现方法(合集
- django @login_required
- 采用easyui tree编写简单角色权限代码的方法
- iOS-UI-02 UILabel UIButton
- ioS -UI-菜单栏的实现
- fifa 15 xbox one coins live quite feints
- PAT (Advanced Level) 1062. Talent and Virtue (25) 德才论,结构体排序
- [Jenkins] 执行SoapUI的task,设置邮件内容为HTML+CSS
- leetCode 96.Unique Binary Search Trees (唯一二叉搜索树) 解题思路和方法
- hdu 2734(Quicksum)
- iPad开发 - UIPopoverController控制器