博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIView
阅读量:7082 次
发布时间:2019-06-28

本文共 2355 字,大约阅读时间需要 7 分钟。

    //1.创建window

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    
    //2.设置window的属性(例如:背景颜色)
    self.window.backgroundColor = [UIColor whiteColor];
    
    //3.设置window为主窗口,并显示
    [self.window makeKeyAndVisible];
    /*
        //步骤1.开辟内存,并初始化(坐标和尺寸)
    UIView *yelloView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
        //步骤2.设置视图的属性
    [yelloView setBackgroundColor:[UIColor yellowColor]];
        //步骤3.添加到window
    [self.window addSubview:yelloView];
        //步骤4.释放内存
    [yelloView release];

        //(50, 200, 100, 100) 蓝色

    
    UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(50, 200, 100, 100)];
        //背景颜色默认是透明的 (cleanColor)
    blueView.backgroundColor = [UIColor blueColor];
    [self.window addSubview:blueView];//添加子视图
    [blueView release];
    
        //移除子视图
//    [blueView removeFromSuperview];

 

     //frame:是父视图的坐标系

        //改变父视图的位置,子视图也跟着移动
    UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(20, 30, 50, 50)];
    greenView.backgroundColor = [UIColor greenColor];
    [blueView addSubview:greenView];
    [greenView release];
    
    blueView.frame = CGRectMake(100, 250, 100, 100);
    
        //center :基于父视图的坐标系
    NSLog(@"%@", NSStringFromCGPoint(yelloView.center));
        //center.x = frame.origin.x + frame.size.width / 2;
        //center.y = frame.origin.y + frame.size.height / 2;
    
    //  bounds:基于自身的坐标系
    NSLog(@"%@", NSStringFromCGRect(yelloView.bounds));
        //frame,center,bounds
        //frame,bounds:CGRect
        //center:CGPoint
    
        //改变frame,影响centerbounds
        //改变center,bounds不变,影响frame
        //改变bounds,center不变,影响frame
    NSLog(@"改变前");
    NSLog(@"%@",NSStringFromCGRect(yelloView.frame));
    NSLog(@"%@", NSStringFromCGPoint(yelloView.center));
    NSLog(@"%@", NSStringFromCGRect(yelloView.bounds));
    
    yelloView.frame = CGRectMake(100, 100, 100, 100);
    NSLog(@"改变后");
    NSLog(@"%@",NSStringFromCGRect(yelloView.frame));
    NSLog(@"%@", NSStringFromCGPoint(yelloView.center));
    NSLog(@"%@", NSStringFromCGRect(yelloView.bounds));
    
    
    
//    hidden 显隐性,默认为NO
//YES 代表隐藏, 隐藏会影响子视图
    cView.hidden = YES;
        //不透明度 alpha.默认值是1.0
        //值越小,越透明,影响子视图
    aView.alpha = 0.5;
    aView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0 alpha:0.5];//仅改变该视图的alpha的透明度
//    aView.subviews
//    aView.superview
        //tag为视图添加整型标签,父视图可以通过标签,找到子视图
        //一般tag要大于100,避免和系统相同,并且tag要做到不重复(同一个父视图内)
    UIView *findView = [_window viewWithTag:1000];

        //__function__打印的的是函数的名字 __line__函数所在的行数

 

转载于:https://www.cnblogs.com/tian-sun/p/4309624.html

你可能感兴趣的文章
mac基本命令
查看>>
IOC疑惑
查看>>
爱上一匹野马
查看>>
ADS的使用
查看>>
STL的string和wstring
查看>>
[ucgui] 仪表盘函数
查看>>
windows下的Nginx+Squid+Tomcat+Memcached集群
查看>>
Javascript玩转继承(一)
查看>>
[问题2014S15] 解答
查看>>
为人处世
查看>>
ios开发中用过的一些外部库总结 cocoapods list
查看>>
wcf系列5天速成——第一天 binding的使用(1)
查看>>
如何解决谷歌Chrome浏览器空白页的问题
查看>>
XSS检测工具 X5S/fiddler
查看>>
Linux守护进程的编程实现
查看>>
Linux查看端口信息命令
查看>>
jq中写PHP
查看>>
jsp EL 表达式
查看>>
问题-Delphi编译时提示缺少delphi自己的单元文件
查看>>
四个 服务器设计模型(42)
查看>>