码迷,mamicode.com
首页 > 移动开发 > 详细

IOS7 导航栏适配

时间:2015-03-20 10:39:45      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

问题:

Appdelegate中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    

    ViewController *VC=[[ViewController alloc]init];

    UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:VC];

    nav.view.backgroundColor = [UIColor blueColor];

    self.window.rootViewController=nav;

    return YES;

}

 在ViewController中:

- (void)viewDidLoad {
    [super viewDidLoad];
//    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
//    {
//        self.edgesForExtendedLayout = UIRectEdgeNone;
//    }
//    self.navigationController.navigationBar.translucent=NO;
    self.view.backgroundColor=[UIColor clearColor];
    UIScrollView *segmentScorllView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 164, self.view.frame.size.width, 44)];
    segmentScorllView.backgroundColor=[UIColor greenColor];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:CGRectMake(0, 0, 50, 44)];
    [button setTitle:@"AAA" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    button.backgroundColor = [UIColor brownColor];
    [button.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [segmentScorllView addSubview:button];
    [self.view addSubview:segmentScorllView];
}

运行效果:

 技术分享

理想运行结果:

技术分享

原因:

在IOS7中屏幕的起始坐标包括导航状态栏

解决方法:

将上面代码的两个注释去除任一注释

 

IOS7 导航栏适配

标签:

原文地址:http://www.cnblogs.com/cuiyw/p/4352798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!