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

IOS7适配 总结

2014-02-21 16:00 232 查看
#define IsIOS7 ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue] >= 7)
if (IsIOS7) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}

自定义返回按钮 控制了位置
-(UIButton *)setNavigationBarBackButtonItem
{
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setFrame:CGRectMake(0, 3, 10, 16)];
[backButton setBackgroundImage:[UIImage imageNamed:@"bews_back_icon.png"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backButton];
return backButton;
}




对iOS7 中tableView显示在 Navigation里面的适配方式

- (void)viewDidAppear:(BOOL)animated
{
if (kIS_IOS7) {
self.edgesForExtendedLayout=UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars=NO;
self.automaticallyAdjustsScrollViewInsets=NO;
}
}

- (void) viewDidLayoutSubviews {
// only works for iOS 7+
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CGRect viewBounds = self.view.bounds;
CGFloat topBarOffset = self.topLayoutGuide.length;

// snaps the view under the status bar (iOS 6 style)
viewBounds.origin.y = topBarOffset * -1;

// shrink the bounds of your view to compensate for the offset
viewBounds.size.height = viewBounds.size.height + (topBarOffset * -1);
self.view.bounds = viewBounds;
}
}


在ios7上UITableView底线右移了,我们可以通过添加代码来让它铺满整个屏幕的宽,在使用前要加上判断是否有这个方法,因为只有ios7以上才有。
if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[_tableView setSeparatorInset:UIEdgeInsetsZero];
}

iOS7 tabbar 阴影线问题
在ios7的tabbar上会出现一条阴影线,想要去掉这条阴影线我们可以加以下代码
[self.tabBar setClipsToBounds:YES];

如果我们的高度是高于49的话,可以使用,这时要判断是不是ios6以上的系统,不然会出现crash情况。
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6)
{
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
}
这样那条黑线就会不见了。


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