iOS入门(二十四)UIView

本文深入探讨了iOS开发中的Swift编程语言,分享了实际项目中使用的高效编码实践和最佳编程习惯,帮助开发者提高开发效率并确保代码质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UIView 
第一类:互联网两大核心技术 :  即时通讯  视频
第二类:面向对象不同(市场细分): eg :面向女性的应用
第三类:新闻类
音频
团购(用户体验,信息罗列)
购物
阅读
地图
目前移动互联网最暴利:手机游戏

command + 1 最大 +2 正常 +3 最小
3.5寸屏   物理尺寸 :320*480    像素尺寸: 640*960
4寸屏  320*568
UIView的层级关系
frame 相对于父视图定义自己的位置
bounds 改变自己的位置关系(现在的原点相对于新的坐标系来说)改变尺寸大小时,保持中心点不变(不改变它的位置)
center 相对于父视图 确定中心点位置


    //建立一个UIWindow的对象, 并让它和屏幕一样大。

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

    //设置window的背景颜色

    self.window.backgroundColor = [UIColor darkGrayColor];

    //如何创建UIView

    //CGRect 规定了一个矩形的位置和大小

    CGRect rect = {{10,20},{300,300}};

    UIView * view1 = [[UIView alloc]initWithFrame:rect];

    //把view贴到window上

    [self.window  addSubview:view1];

    [view1 setBackgroundColor  [UIColor blackColor] ];

    [view1 release];

    CGRect rect2 = CGRectMake(10, 10, 280, 280);

    UIView * view2 = [[UIView alloc]initWithFrame:rect2];

    view2.backgroundColor = [UIColor blueColor];

    [view1 addSubview:view2];

    [view2 release];

    //设置为主window并且可见

    [self.window makeKeyAndVisible];


 

    //根据中心点重新设置矩形的位置

//    view2.center = CGPointMake(100, 100);

//    view2.bounds = CGRectMake(20, 20, 250, 250);

    UIView * view3 = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 250, 250)];

    [_window addSubview:view3];

    view3.backgroundColor = [UIColor purpleColor];

    [view3 release];

    UIView * view4 = [[UIView alloc]initWithFrame:CGRectMake(200, 200, 200, 250)];

    view4.backgroundColor = [UIColor blueColor];

//    [view1 insertSubview:view4 atIndex:0];

//    [view1 insertSubview:view4 belowSubview:view2];

    [_window addSubview:view4];

    [view4 release];

    [_window sendSubviewToBack:view1];

    view4.hidden = NO;

    view3.alpha = 0.5;

    UIView * view5 = [view4 superview];

    view5.backgroundColor = [UIColor brownColor];

    [view5 release];

    NSArray * views = [_window subviews];

    UIView * view6 = [views objectAtIndex:1];

    view6.backgroundColor = [UIColor cyanColor];

//    view6.center = CGPointMake(150, 150);

    UIView * view7 = [view4.superview.subviews firstObject];

    view7.backgroundColor = [UIColor blackColor];

    view1.tag = 100;

    [[_window viewWithTag:100] setBackgroundColor:[UIColor greenColor]];

    

    UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 50, 20)];

    label1.backgroundColor = [UIColor blackColor];

    [_window addSubview:label1];



 

//    UIView * aview = [[UIView alloc]initWithFrame:CGRectMake(20, 40, 120, 240)];

//    aview.backgroundColor = [UIColor yellowColor];

//    [_window addSubview:aview];

//    [aview release];

//    UIView * bview = [[UIView alloc]initWithFrame:CGRectMake(40, 60, 120, 240)];

//    bview.backgroundColor = [UIColor greenColor];

//    [_window addSubview:bview];

//    [bview release];

//    UIView * cview = [[UIView alloc]initWithFrame:CGRectMake(60, 80, 120, 240)];

//    cview.backgroundColor = [UIColor brownColor];

//    [_window insertSubview:cview atIndex:1];

//    [cview release];

//    UIView * dview = [[UIView alloc]initWithFrame:CGRectMake(80, 100, 120, 240)];

//    dview.backgroundColor = [UIColor blueColor];

//    [_window insertSubview:dview aboveSubview:aview];

//    [dview release];

//    UIView * eview = [[UIView alloc]initWithFrame:CGRectMake(100, 120, 120, 240)];

//    eview.backgroundColor = [UIColor magentaColor];

//    [_window insertSubview:eview belowSubview:bview];

//    [eview release];

        [_window bringSubviewToFront:aview];

    [_window sendSubviewToBack:bview];

    [_window exchangeSubviewAtIndex:3 withSubviewAtIndex:4];

    [dview removeFromSuperview];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值