0
我已经开始开发没有界面构建器的iOS。iOS UIViewController布局问题
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];
}
我不知道为什么,但是当我加载应用程序,有顶蚂蚁钮和视图之间的空间。有没有人有一个想法,为什么?
您需要将[email protected]背景图片添加到项目 – 2014-12-09 12:15:05
我刚刚在6加模拟器中运行您的代码。我没有看到黑色区域 – humblePilgrim 2014-12-09 12:18:55
@Gonji Dev,您的回答是正确的!如果您发布它,我会将其标记为正确! – 2014-12-09 12:21:07