UIView的简单实用

在IOS UI中UIView的简单使用的方法

UIView的使用
1、创建:UIView *view = [[UIView alloc]init];//创建坐标为(0,0),宽高均为0的视图
   UIView *view = [[UIView alloc] initWithFrame: CGRectMake(10, 10, 100, 50)];//创建一个相对父视图坐标为(10,10),宽100,高50的视图

2、 view.frame = CGRectMake(20, 10, 100, 50);//设置view的坐标及尺寸

3、 view.userInteractionEnabled = NO;//是否响应用户交互(触摸)

4、 view.tag = 1;//设置视图的标签

5、 UIView *view3 = [view viewWithTag:1];//将view子视图中标签为3的视图赋值给view3

6、  -(void) addSubview:(UIView *)view;//添加子视图   

     [view addSubview:view2];将view2加到view上

7、  -(void) removeFromSuperview;//从父窗口上删除子视图(自己)

    [view removeFromSuperview];

8、   [view insertSubview:view1 atIndex:0];//在view的第0层插入一个子视图

9、  [view insertSubview:view1 belowSubview:view2]; //将view1子视图添加到view2子视图下

10、   [view insertSubview:view1 aboveSubview:view2]; //将view1子视图添加到view2子视图下

11、   view.backgroundColor = [UIColor whiteColor];//设置背景色

12、  view.alpha = 1;//设置view的透明度,0~1透明到不透明

13、  view.hidden = YES;//是否隐藏view
posted on 2015-11-09 14:51  沙->仙人掌  阅读(114)  评论(0编辑  收藏  举报