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];
}
}
- (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];
}
}
相关文章推荐
- IOS开发-Xcode如何设置根视图
- iOS 声明属性关键字讲解
- IOS tableView 选中时的背景颜色设置
- 关于IOS深浅拷贝的深入分析
- 利用iOS动画来模拟音量振动条的实现
- [随 笔]iOS提醒笔记
- IOS开发-CGAffineTransform的用法,实现一些简单动画效果
- IOS -自定义半透明View
- iOS开发系列--地图与定位
- ios-AFNetworking2.5
- iOS开发 贝塞尔曲线
- IOS开发之修改icon
- ios NSScanner 扫描字符串获取相应的需要的字符串
- iOS8 Core Location (授权。。。室内定位。。。访问监控。。。)
- 单例模式的简单创建
- IOS消息推送之APNS
- IOS合并lib(.a)库的终极可用方法(可用于解决duplicate symbol静态库冲突)
- IOS - 关于我们页面
- 给xcode6添加空工程(iOS)
- iOS collectionView自定义head和foot