zoukankan      html  css  js  c++  java
  • UIView的基本用法

     //1.初始化视图  确定矩形的坐标(x,y) 宽高
        self.myView=[[UIView alloc] initWithFrame:CGRectMake(100, 50, 200, 400)];
       
        //2.设置背景色
        self.myView.backgroundColor=[UIColor blackColor];
       
        //3.添加子视图到view(父视图)上
        [self.view addSubview:self.myView];
        //添加父视图(view)背景颜色
        self.view.backgroundColor=[UIColor purpleColor];
       
        //4.判断设备屏幕大小
        CGRect rectView=self.view.frame;
        NSLog(@"%@",NSStringFromCGRect(rectView));
       
        //5.fram相对于父视图的坐标位置 能知道坐标和大小
        NSLog(@"myView.fram : %@",NSStringFromCGRect(self.myView.frame));
       
        //6.bounds 只是显示当前视图的大小 不知道坐标
        NSLog(@"myView.bounds: %@",NSStringFromCGRect(self.myView.bounds));
       
        //7.center 控件相对于父视图的中心坐标
        NSLog(@"%@",NSStringFromCGPoint(self.myView.center));
       
        //8.设置视图中心点坐标
        self.myView.center=CGPointMake(300, 350);
       
        //9.改变视图边界
        self.myView.bounds=CGRectMake(0, 0, 50, 50);
     
        //10.水平方向平移200个点
        self.myView.transform=CGAffineTransformMakeTranslation(200, 0);
     
        //11.垂直方向平移200个点
        self.myView.transform=CGAffineTransformMakeTranslation(0, 200);
     
        //12.斜方向平移
        self.myView.transform=CGAffineTransformMakeTranslation(10, 200);
       //13.设置隐藏视图
        self.myView.hidden=YES;
     
        //14.如果子视图超出父视图范围是否裁剪子视图  默认是NO
        self.myView.clipsToBounds=YES;
     
        //15.是否可以和用户进行交互,默认为YES
        self.myView.userInteractionEnabled=YES;
     
       //初始化视图aView ,bView ,cView
        self.aView=[[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
        self.aView.backgroundColor=[UIColor redColor];
      
        self.bView=[[UIView alloc] initWithFrame:CGRectMake(150, 150, 200, 200)];
        self.bView.backgroundColor=[UIColor purpleColor];
       
        self.cView=[[UIView alloc] initWithFrame:CGRectMake(200, 200, 200, 200)];
        self.cView.backgroundColor=[UIColor blackColor];
        //1.添加子视图
        [self.view addSubview:self.aView];
        [self.view addSubview:self.bView];
        [self.view addSubview:self.cView];
        //插入指定视图 在xxx视图的下面
        [self.view insertSubview:self.bView aboveSubview:self.aView];
        //在xxx视图上面
        [self.view insertSubview:self.bView belowSubview:self.aView];
        //在指定索引位置插入视图
        [self.view insertSubview:self.bView atIndex:0];
        //交换子视图的索引位置
        [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];
        //将子视图放到最后
        [self.view sendSubviewToBack:self.cView];
        //将子视图放到最前
        [self.view bringSubviewToFront:self.aView];
       
  • 相关阅读:
    Google Chrome 自定义协议(PROTOCOL)问题的处理
    C# 6.0/7.0 的新特性
    MySQL 5.7.18 压缩包版配置记录
    nginx.conf文件内容详解
    博客添加动态动漫妹子
    TypeScript 3.8beta版
    微信浏览器H5开发常见的坑
    Babel7知识梳理
    雅虎前端优化35条规则
    webpack
  • 原文地址:https://www.cnblogs.com/zhaochaobin/p/5253944.html
Copyright © 2011-2022 走看看