您的位置:首页 > 产品设计 > UI/UE

iOS UI 视图

2015-06-24 09:02 441 查看
//创建一个window,并将window设置全屏。
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds] ];
[self.window  setBackgroundColor: [UIColor redColor]];
//创建一个view
//第一步 开辟内存空间并初始化
UIView * backgroundView = [[UIView alloc] init];
//第二步 设置控件坐标大小
[backgroundView setFrame:CGRectMake(50,50, 100,200)];
//第三步 控件基本设置
[backgroundView setBackgroundColor:[UIColor blackColor]];
//第四步 添加视图(将backgroundView 添加到 self.window上)
UIView * backgroundView1 = [[UIView alloc] init];
[backgroundView1 setFrame:CGRectMake(100, 200, 50, 50)];
[backgroundView1 setBackgroundColor:[UIColor whiteColor]];
UIView * bgview = [[UIView alloc] initWithFrame:CGRectMake(50, 200, 50, 50)];
[bgview setBackgroundColor:[UIColor lightGrayColor]];
UIView * bgview1 = [[UIView alloc] initWithFrame:CGRectMake(75, 175, 50, 50)];
[bgview1 setBackgroundColor:[UIColor darkGrayColor]];
UIView * bgCenter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[bgCenter setCenter:CGPointMake(self.window.frame.size.width / 2, self.window.frame.size.height / 2)];//屏幕中心
[bgCenter setBackgroundColor:[UIColor purpleColor]];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setBackgroundColor:[UIColor whiteColor]];
UIView * bg1 = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 10, 10)];
[bg1 setBackgroundColor:[UIColor redColor]];
UIView * bg2 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 20, 20)];
[bg2 setBackgroundColor:[UIColor blueColor]];
UIView * bg3 = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 30, 30)];
[bg3 setBackgroundColor:[UIColor purpleColor]];
UIView * bg4 = [[UIView alloc] initWithFrame:CGRectMake(80, 80, 200, 200)];
[bg4 setBackgroundColor:[UIColor yellowColor]];
UIView * bg5 = [[UIView alloc] initWithFrame:CGRectMake(60, 60, 100, 100)];
[bg5 setBackgroundColor:[UIColor greenColor]];
for (UIView * view in self.window.subviews) {
NSLog(@"view = %@",view);
}
[bg4 setHidden:NO];//显示或者隐藏
//alpha 透明度设置0~1
[bg4 setAlpha:0.5];
//获取父视图
UIView * superView = [bg4 superview];
NSLog(@"super= %@",superView);
[bg3 setTag:50];
UIView * tagView = [self.window viewWithTag:50];
NSLog(@"tag = %@",tagView);
[self.window bringSubviewToFront:bg5];//将视图显示在最前面取决语句位置
[self.window sendSubviewToBack:bg3];//显示在最后面取决语句位置
[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];//交换两个指定索引位置的子视图
[self.window addSubview:bg1];
[self.window addSubview:bg2];
[self.window addSubview:bg3];
[self.window insertSubview:bg4 atIndex:1];//将视图插入到
[self.window insertSubview:bg5 belowSubview:bg4];//above上面覆盖,below下面
[self.window addSubview:backgroundView1];
[self.window addSubview:bgview];
[self.window addSubview:bgview1];
[self.window makeKeyAndVisible];
[self.window addSubview:bgCenter];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios ui uiview