zoukankan      html  css  js  c++  java
  • iOS--UIView和UIWindow用法

    • 基础
    • UI(user interface)是用户界面;iOS的应用是由各种各样的UI控件组成
    • UIWindow就是一个窗口,学的第一个基础类,就是一个容器,可以在容器上放不同的内容,每个app都需要借助Window将内容展现给用户
    • UIView是视图,代表屏幕上的一个矩形区域
    • UIView和UIWindow除了继承外没有其他关系,window是窗口,上面赋着UIView,平常看不见UIWindow,我们用的self是系统建的UIView
    • 一般不要直接在UIWindow上直接加视图
    • 创建视图:1、开辟空间并初始化视图(给出位置和大小)2、对视图做一些设置(如背景颜色)3、将视图添加到window上进行显示 [self.window addSubview:blueView]4、释放视图对象、
    • 常用属性
      • window的属性
      • view的属性有:
      • backgroundColor
      • frame
      • rootViewController
      • userInteractionEnabled
      • screen
      • backgroundColor
       
      • tag
       
       
      • alpha
       
      • hidden
       
      • superview
       
      • subviews
    • 创建          self.window = [[UIWindow alloc] initWithFrame:  [UIScreen mainScreen].bounds];//创建window,让其充满屏幕。       [self.window makeKeyAndVisible];//让其成为主窗口且可视
    •     self.window.backgroundColor = [UIColor whiteColor];//设置背景颜色
    •     self.window.rootViewController = [[ViewController alloc] init];//设置根视图控制器,要加头文件
    •    
    •     //流程:main->app->view->
    • //*添加子视图*
    •     self.view.backgroundColor = [UIColor redColor];
    •     UIView *view = [[UIView alloc] init];
    •     view.frame = CGRectMake(10, 20, 30, 40);//相对于父视图的位置,注意坐标和尺寸的合理性,保证坐标加尺寸不会超出俯视图范围。
    •     view.userInteractionEnabled = NO;//是否允许用户点击,如果设置成NO,子视图不会覆盖父视图的点击事件
    •     self.view.userInteractionEnabled = NO;//如果父视图不允许交互,子视图事件也会被屏蔽。
    •     view.backgroundColor = [UIColor whiteColor];
    •     [self.view addSubview:view];//将后面的视图添加到前面的视图之上
    •     view.tag = 1;//设置视图标签
    •     UIView *view3 = [self.view viewWithTag:1];//获取父视图中标签为一的视图。
    •     view.alpha = 0;//设置视图的透明度,0~1浮点
    •     self.view.alpha = 0;//如果父视图透明,子视图也会看不见
    •     view.hidden = YES;//设置视图是否隐藏
    •     self.view.hidden = YES;//如果父视图被隐藏,子视图也会被隐藏
    •    操作
    •          NSArray*subviews = [redview subviews];//获得本视图的  所有子视图
    •              UIView*superview = [redview superview];//获取本视图的父视图
    •     [view removeFromSuperview];//移除
    •     [self.view insertSubview:view atIndex:1];//将子视图添加到父视图的某个位置
    •     [self.view insertSubview:view2 aboveSubview:view];//将view1添加到父视图且在view之上
    •     [self.view insertSubview:view2 belowSubview:view];//将view1添加到父视图且在view之下。
    •     [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];//交换两个位置的视图
    •     [self.view bringSubviewToFront:view];//将某个子视图移到父视图的最前面
    •     [self.view sendSubviewToBack:view2];//将某个子视图移到父视图最底层
    • 被点击的方法-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    •                                  NSLog(@"被点击");
    •                             }
  • 相关阅读:
    爬虫案例
    伪静态
    HTTP0.9、HTTP1.0、HTTP1.1、HTTP2的区别
    正向代理和反向代理
    数据结构继承
    APP 爬虫
    算法基础
    matplotlib
    Java类加载机制及自定义加载器
    SpringBoot war包部署到Tomcat服务器
  • 原文地址:https://www.cnblogs.com/zyz1341320997/p/4951848.html
Copyright © 2011-2022 走看看