【发布时间】:2014-12-09 12:04:58
【问题描述】:
我已经开始在没有界面生成器的情况下开发 iOS。
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
ViewController *viewController = [[ViewController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
ViewController.m
- (void)loadView
{
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
UIView *contentView = [[UIView alloc] initWithFrame:applicationFrame];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 280, 20)];
[label setText:@"ViewController"];
[label setTextAlignment:NSTextAlignmentCenter];
[label setBackgroundColor:[UIColor redColor]];
[self.view addSubview:label];
}
我不知道为什么,但是当我加载应用程序时,顶部蚂蚁按钮和视图之间有空间。有人知道为什么吗?
【问题讨论】:
-
项目需要添加Default-568h@2x.png背景图片
-
我刚刚在 6 plus 模拟器中运行了您的代码。我没有看到黑色区域
-
@Gonji Dev,你的答案是正确的!如果你发布它,我会标记它为正确的!
标签: ios objective-c iphone uiviewcontroller