IOS界面UI设计7之UIWindown、多种方式创建视图控制器、View

来源:互联网 发布:方正字库 mac 编辑:程序博客网 时间:2024/04/30 15:08

(1)UIWindown的创建

   // 1.创建窗口

   self.window= [[UIWindowalloc]init];

   self.window.frame = [UIScreenmainScreen].bounds;

   // 2.设置颜色

   self.window.backgroundColor = [UIColorredColor];

   // 3.显示窗口

   [self.windowmakeKeyAndVisible];

    // 4.添加一个按钮

   [self.windowaddSubview:UIButton];

(2)视图控制器创建

2.1 创建一个UIViewcontroller

       OneViewController*one = [[OneViewControlleralloc]init];

       one.view.backgroundColor = [UIColorblueColor];

       self.window.rootViewController= one;

2.2 加载StoryBoard中的UIViewcontroller

默认加载箭头指向的、或者如下设置:


    // 加载storyboard

UIStoryboard *storyboard = [UIStoryboardstoryboardWithName:@"Two"bundle:nil];

UIViewController *two =[storyboardinstantiateInitialViewController]

    TwoViewController *two = [storyboardinstantiateViewControllerWithIdentifier:@"xxx"];

    self.window.rootViewController = two;

two有两种添加方式,要么使用instantiateInitialViewController,默认加载storyboard中箭头指向的UIViewcontroller,要么加载自定义名字的:xxx

2.3 创建工程的时候创建一个 单视图的,这个时候默认加载创建的Storyboard。


2.4 xib创建

    ThreeViewController *three = [[ThreeViewControlleralloc]initWithNibName:@"xibname"bundle:nil];

    self.window.rootViewController = three;

3 view

3.1代码加载view

(1)- (void)loadView

ios中只要在viewcontroller中有这个方法,就会将其他的view视图加载方法否屏蔽掉,这个代码复写了view视图的创建方法。

3.2 

(2)通过xib加载view。

首先创建一个xib,注意这里xib中既可以添加UIViewcontroller,也可以添加一个view。添加view的时候,需要注意file owner等几个属性的设置。

    OneViewController *one = [[OneViewControlleralloc] initWithNibName:@"xxxx"bundle:nil];

    // 设置窗口的根控制器

self.window.rootViewController = one;



0 0