码迷,mamicode.com
首页 > 移动开发 > 详细

UIview 学习与自定义--ios

时间:2014-08-26 01:42:45      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:blog   color   os   io   div   log   sp   ad   c   

    
    UIView *view1=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
    view1.backgroundColor=[UIColor yellowColor];
    view1.tag=1;
    [self.window addSubview:view1];
    
    UIView *view2=[[UIView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
    view2.backgroundColor=[UIColor greenColor];
    view2.tag=2;
    view2.alpha=0.2;//更改透明度,会影响到子视图显示
    [view1 addSubview:view2];//视图嵌套
    
    UIView *view3=[[UIView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
    view3.backgroundColor=[UIColor grayColor];
    view3.tag=3;
    [view2 addSubview:view3];//视图3颜色受父类影响
    
    UIView *view5=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 30, 30)];
    view5.backgroundColor=[UIColor grayColor];
    view5.tag=5;
    [view1 addSubview:view5];
    
    UIView *view4=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    view4.backgroundColor=[UIColor blackColor];
    view4.hidden=YES;//隐藏视图,也会影响到子类
    [view1 addSubview:view4];
    
    UIView *view6=[[UIView alloc] initWithFrame:CGRectMake(80, 80, 10, 10)];
    view6.backgroundColor=[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5];//
    [view1 addSubview:view6];
    
    UIView *view=[self.window viewWithTag:2];//通过tag获取指定视图
    view.backgroundColor=[UIColor redColor];
    
    //自定义视图
    MyView *myview=[[MyView alloc] initWithFrame:CGRectMake(150, 150, 100, 100)];
    [self.window addSubview:myview];
    
    [self.window makeKeyAndVisible];

 

UIview 学习与自定义--ios

标签:blog   color   os   io   div   log   sp   ad   c   

原文地址:http://www.cnblogs.com/clarence/p/3936246.html

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