第二课 (3)元素在界面上
接着上次的代码看上边的
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
前面很好理解,APPDelegate调用window的属性
后面的“[UIScreen mainScreen].bounds”换成“XXX”
[[UIWindow alloc] initWithFrame:XXX
类对象 方法 方法 参数,的组合。
"initWithFrame:XXX"是指在某一个尺寸范围内初始化。
"XXX"=[UIScreen mainScreen].bounds
类对象 方法 属性:尺寸
后面这句话的意思是:当前屏幕尺寸范围内
回过头来再看语句,就非常容易理解
UIWindow有一个实例对象,在一定的尺寸范围之内做初始化,在什么范围内呢?就在当前的屏幕尺寸范围内。
[self.window makeKeyAndVisible];
makeKeyAndVisible是self.window的方法
大意是,让我们创建的窗口为一个可见的窗口并且是主窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; ViewController *rootView = [[ViewController alloc] init]; UINavigationController * navigation = [[UINavigationController alloc] initWithRootViewController:rootView]; self.window.rootViewController = navigation; [self.window makeKeyAndVisible];
这就是最近这两次博客里写的代码,目的是让启动页面挂在导航栏下呈现给用户
我们修改一下导航栏的文字颜色
在ViweController.m里添加代码
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 44)]; titleLabel.text = title; titleLabel.textColor = [UIColor whiteColor]; titleLabel.font = [UIFont boldSystemFontOfSize:17]; titleLabel.textAlignment = NSTextAlignmentCenter; titleLabel.backgroundColor = [UIColor clearColor]; self.navigationItem.titleView = titleLabel;
就ok了