• iOS阶段学习第28天笔记(UIView的介绍)


    iOS学习(UI)知识点整理

    一、关于UIVIew 的介绍

    1)概念:UIView 是用于装载并展示各类控件的大容器,是iOS中所有UI控件的基类

    2)UIView  初始化实例代码 

     1 UIView *view1 = [[UIView alloc] init];
     2 view1.frame = CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height/2);
     3 view1.backgroundColor = [UIColor lightGrayColor];
     4 view1.tag = 1000;
     5 
     6 //alpha属性设置view的透明度
     7 view1.alpha = 0.5;
     8 
     9 //超出部分自动隐藏
    10 view1.clipsToBounds = YES;
    11 [self.view addSubview:view1];

    3)sendSubviewToBack 父视图可以使用sendSubviewToBack方法将子视图放在最下层
    例如: 

    1  UIView *view3 = [[UIView alloc] init];
    2  view3.frame = CGRectMake(45, 45, 240, 260);
    3  view3.backgroundColor = [UIColor blueColor];
    4  view3.tag = 1001;
    5  [view1 addSubview:view3];
    6     
    7  //父视图把某一子视图放在最下层
    8  [view1 sendSubviewToBack:view3];

     
    4)bringSubviewToFront 父视图可以使用sendSubviewToBack方法将子视图放在最上层
    例如: 

    1 UIView *view2 = [[UIView alloc] init];
    2 view2.frame = CGRectMake(40, 40, 250, 250);
    3 view2.backgroundColor = [UIColor blackColor];
    4 view2.tag = 1001;
    5 [view1 addSubview:view2];
    6 
    7  //父视图把某一子视图放在最上层
    8  [view1 bringSubviewToFront:view2]; 

     
    5)获取self.view中所有的子视图  例如: 

    1  NSArray *subViews = self.view.subviews;

    6)removeFromSuperview 将子视图从父视图中移除 例如: 

    1  [view1 removeFromSuperview];

     
    7) viewWithTag 根据视图Tag标记获取视图 例如:

    1  UIView *view = [self.view viewWithTag:1000];

     
    8) hidden 隐藏视图 例如: 

    1   view.hidden = YES;

    9)因为所有的UI控件都继承自UIVIew 所以根据控件的Tag标记可以使用viewWithTag获取控件对象

      例如:

    1 //1000 为button的Tag标记 注意:需要强转一下
    2 UIButton *button=(UIButton*)[self.view viewWithTag:1000];
  • 相关阅读:
    Mysql 创建联合主键
    Shell中的while循环
    shell 日期加减运算
    PHP日期格式转时间戳
    Uber 叫车时,弹出以下代码导致无法打车(An email confirmation has been sent to...),解决办法
    如何让Table显示滚动条
    mySQL中replace的用法
    打豪车应用:uber详细攻略(附100元优惠码)
    svn 命令行创建和删除 分支和tags
    php ob_start()、ob_end_flush和ob_end_clean()多级缓冲
  • 原文地址:https://www.cnblogs.com/ChinaKingKong/p/4689746.html
Copyright © 2020-2023  润新知