问题:
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中屏幕的起始坐标包括导航状态栏
解决方法:
将上面代码的两个注释去除任一注释