码迷,mamicode.com
首页 > 其他好文 > 详细

Ui——创建视图的方法及过程

时间:2016-03-07 22:12:34      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

      //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];
}

Ui——创建视图的方法及过程

标签:

原文地址:http://www.cnblogs.com/guiyangxueyuan/p/5252047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!