iPhone開發(fā)當(dāng)中忍些,有時(shí)需要獲取狀態(tài)欄和導(dǎo)航欄高度、寬度信息,方便布局其他控件两曼。下面介紹一下如何獲取這些信息:
// 狀態(tài)欄(statusbar)
CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
NSLog(@"status width - %f", rectStatus.size.width); // 寬度
NSLog(@"status height - %f", rectStatus.size.height); // 高度
// 導(dǎo)航欄(navigationbar)
CGRect rectNav = self.navigationController.navigationBar.frame;
NSLog(@"nav width - %f", rectNav.size.width); // 寬度
NSLog(@"nav height - %f", rectNav.size.height); // 高度
打印結(jié)果如下:
2015-01-14 13:22:22.206 app_name[226:60b] status width - 320.000000
2015-01-14 13:22:22.209 app_name[226:60b] status height - 20.000000
2015-01-14 13:22:22.210 app_name[226:60b] nav width - 320.000000
2015-01-14 13:22:22.211 app_name[226:60b] nav height - 44.000000