这是一个在屏幕顶部显示蓝色视图的简单程序。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
UIViewController* vc = [[UIViewController alloc] init];
CGFloat y = 20;
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
y = 0;
}
UIView* sample = [[UIView alloc] initWithFrame:CGRectMake(0, y, 768, 100)];
sample.backgroundColor = [UIColor blueColor];
[vc.view addSubview:sample];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
如果 iOS 版本为 7 或 6 及以下,我有逻辑将 y 变量设置为 0 或 20。有一个更好的方法吗?