zoukankan      html  css  js  c++  java
  • Ui——创建视图的方法及过程

          //1.创建视图

    ViewController.h

    @interface ViewController : UIViewController

    //创建视图控件;

    @property(strong,nonatomic)UIView *myView;

    @end

    ViewController.m

    @interface ViewController ()

     

    @end

     

    @implementation ViewController

    - (void)viewDidLoad

    {

           [super viewDidLoad];

    //结构体  确定矩形的区域,x,y,wedth,height;
        CGRect rect=CGRectMake(10,10, 150, 500);//(x,y,w,h)
               //实例化视图对象并指定视图区域;
        UIView *myView=[[UIView alloc]initWithFrame:rect];
        myView.backgroundColor=[UIColor redColor];//设置背景色;
        [self.view addSubview:myView];//添加子视图带view上;
     
     
     
         //查看视图View的CGRect。。。。。
    / //frame(框架)  相对于父视图的坐标及大小  bounds(界限) 只是显示当前视图的大小
    //法1  。。。父视图view的frame;
        CGRect rectView=self.view.frame;
        NSLog(@"View.freme:%@",NSStringFromCGRect(rectView));
       
      //法2 
    //子视图myView的frame;
    NSLog(@"myView.freme:%@",NSStringFromCGRect(self.myView.frame));
       
    //子视图myView的bounds视图界限,坐标从(0,0)开始
     NSLog(@"myView.bounds:%@",NSStringFromCGRect(self.myView.bounds));
        //子视图myView的center中心点的坐标。。。。。。
        NSLog(@"%@",NSStringFromCGPoint(self.myView.center));
       
        //移动创建的子视图的位置(及改变中心点center的坐标Point);
        self.myView.center=CGPointMake(100, 100);
        //改变创建子视图的边界;
        self.myView.bounds=CGRectMake(0, 0, 150, 150);
     }
     
     
                     // 2.视图的一些排版方法;
    ViewController.h
    @interface ViewController : UIViewController
    @property(strong,nonatomic)UIView *aView;
    @property(strong,nonatomic)UIView *bView;
    @property(strong,nonatomic)UIView *cView;
    @end
     
    ViewController.m
    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
     
    UIView *aView=[[UIViewalloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
        aView.backgroundColor=[UIColor redColor];
        [self.view addSubview:aView];
       
        UIView *bView=[[UIView alloc]initWithFrame:CGRectMake(150, 150, 150, 150)];
        bView.backgroundColor=[UIColor greenColor];
        [self.view addSubview:bView];

       
        UIView *cView=[[UIView alloc]initWithFrame:CGRectMake(200, 200, 100, 100)];
        cView.backgroundColor=[UIColor blueColor];
        [self.view addSubview:cView];
       
        //操作方法。。。。。。。。。。。。。
     
        //插入指定视图放在---的下面
       [self.view insertSubview:bView belowSubview:aView];
        //插入指定视图放在---的上面
       [self.view insertSubview:bView aboveSubview:aView];
       
        //在指定位置插入视图
        [self.view insertSubview:bView atIndex:0];
        //移除视图
        [self.view removeFromSuperview];
        //交换子视图的索引位置;
        [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];
     
       
        //将子视图放到最后
        [self.view sendSubviewToBack:cView];

        ////将子视图放到最前
        [self.view bringSubviewToFront:aView];
    }
  • 相关阅读:
    JVM 垃圾回收器工作原理及使用实例介绍(转载自IBM),直接复制粘贴,需要原文戳链接
    装tomcat和nginx心得
    jms的俩种模式
    裸奔Spring(1)
    一个最小mybatis
    SpringBoot和数据库连接
    SpringBoot的基础Pom
    SpringBoot读取配置文件
    埃拉托斯特尼素数筛法
    hdu 1175 连连看
  • 原文地址:https://www.cnblogs.com/guiyangxueyuan/p/5252047.html
Copyright © 2011-2022 走看看