您的位置:首页 > 移动开发 > IOS开发

iOS禁止横屏,tableView去掉左端默认的15空白像素

2015-07-21 17:18 531 查看
1 禁止横屏

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{

return UIInterfaceOrientationMaskPortrait;

}

2 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];

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: