博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
进击的UI-----------------UIWindow&UIView&UILabel
阅读量:5314 次
发布时间:2019-06-14

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

1.UIWindow
定义初始:
1⃣️:初始化窗口:self.window = [[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]autorelease];
2⃣️:设置背景色:self.window.backgroundColor = [UIColor whiteColor];
3⃣️:让window显示:[self.window makeKeyAndVisible];
2.UIView
1⃣️:定义初始:
①:初始化给大小:    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(200, 200, 50, 50)];
②:设置View的背景色:view2.backgroundColor = [UIColor blueColor];
③让视图显示:    [self.window addSubview:view2];
2⃣️:方法
①:透明度:greenview.alpha = 1;
②:插入到固定位置:[self.window insertSubview:blueview atIndex:1];
③:移到最前:[self.window bringSubviewToFront:redview];
④:移到最后:[self.window sendSubviewToBack:redview];
⑤:交换两个图层:[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
⑥:移走删除图层:[greenview removeFromSuperview];
⑦:隐藏:redview.hidden = YES;// BOOL 默认是NO;
3.UILabel
1⃣️:定义初始:
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 60, 100)];
label1.backgroundColor = [UIColor grayColor];
2⃣️:方法
①:设置文字:label1.text = @"范冰冰";
②:设置文字颜色:label1.textColor = [UIColor redColor];
③:设置文字字体:label1.font = [UIFont fontWithName:@"Georgia" size:17];
④:默认字体:label1.font = [UIFont systemFontOfSize:17];
⑤:对齐
(1):居中对齐:label1.textAlignment = NSTextAlignmentCenter;
(2):向左对齐:label1.textAlignment = NSTextAlignmentLeft;
(3):向右对齐:label1.textAlignment = NSTextAlignmentRight;
⑦:不限制行数:label1.numberOfLines = 0;
⑧:断行模式:label1.lineBreakMode = NSLineBreakByCharWrapping;
⑨:阴影
(1):设置阴影:label1.shadowColor = [UIColor greenColor];
(2):设置阴影偏移量:label1.shadowOffset = CGSizeMake(10, 10);
⑩:通过RGB设置View背景色:label1.backgroundColor = [UIColor colorWithRed:0 green:255 blue:40 alpha:1];
4.frame bonus center
1⃣️:frame:
(1)定义:frame 是一个大小 包含原点(x,y)大小(windth,height)
(2)注意:iphone坐标器以左上角为原点frame是以此坐标系给定的
(3)代码:
    CGPoint point1  = CGPointMake(100, 100);
    CGSize size1= CGSizeMake(100, 100);
    CGRect rect1 = CGRectMake(100, 200, 300, 400);
    NSLog(@"%@",NSStringFromCGPoint(point1));
    NSLog(@"%.0f",point1.x);
    NSLog(@"%0.f",point1.y);
    NSLog(@"%@",NSStringFromCGSize(size1));
    NSLog(@"%.0f",size1.height);
    NSLog(@"%.0f",size1.width);
    NSLog(@"%@",NSStringFromCGRect(rect1));
    NSLog(@"%0.f",rect1.origin.x);
    NSLog(@"%0.f",rect1.size.width);
2⃣️:bonus
(1)定义:bound是是以父视图为原点建立的一个坐标系
(2)代码:
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(100 , 100, 100, 100)];
    view1.backgroundColor = [UIColor redColor];
    [self.window addSubview:view1];
    NSLog(@"%@",NSStringFromCGRect(view1.frame));
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 50, 50)];
    view2.backgroundColor = [UIColor yellowColor];
3⃣️:center
(1)定义:center的坐标是根据父视图求出来的
(2)计算: {x+width/2 y+height/2}
练习题:
1⃣️:
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(20, 100, 100, 30)];
    view1.backgroundColor = [UIColor yellowColor];
    [self.window addSubview:view1];
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame)+20, CGRectGetMinY(view1.frame), 150, 30)];
    view2.backgroundColor = [UIColor blackColor];
    [self.window addSubview:view2];
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMinX(view1.frame), CGRectGetMaxY(view1.frame)+20, CGRectGetWidth(view1.frame), CGRectGetHeight(view1.frame))];
    view3.backgroundColor = [UIColor greenColor];
    [self.window addSubview:view3];
    UIView *view4 = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(view3.frame)+20, CGRectGetMinY(view3.frame), CGRectGetWidth(view2.frame), CGRectGetHeight(view2.frame))];
    view4.backgroundColor = [UIColor redColor];
    [self.window addSubview:view4];
    for (int i = 0; i < 3; i++) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMinX(view3.frame) +95*i, CGRectGetMaxY(view3.frame) + 20, CGRectGetWidth(view1.frame) - 20, CGRectGetHeight(view4.frame))];
        view.backgroundColor = [UIColor greenColor];
        [self.window addSubview:view];
    }
2⃣️:
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 60, 100, 30)];
        label1.text = @"用户名";
        label1.textAlignment =NSTextAlignmentCenter;
        label1.textColor = [UIColor blackColor];
        [self.window addSubview:label1];
        UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label1.frame) + 20, CGRectGetMinY(label1.frame), 150, CGRectGetHeight(label1.frame))];
        label2.backgroundColor = [UIColor grayColor];
        [self.window addSubview:label2];
        UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(label1.frame), CGRectGetMaxY(label1.frame) + 20, CGRectGetWidth(label1.frame), CGRectGetHeight(label1.frame) )];
        label3.text = @"密码";
        label3.textColor = [UIColor blackColor];
        label3.textAlignment = NSTextAlignmentCenter;
        [self.window addSubview:label3];
        UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(label3.frame) +20, CGRectGetMinY(label3.frame), CGRectGetWidth(label2.frame), CGRectGetHeight(label2.frame))];
        label4.backgroundColor = [UIColor grayColor];
        [self.window addSubview:label4];
3⃣️:
(1):
        for (int i = 0; i <  3; i++) {
                for (int j = 0; j < 3; j++) {
                    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20 + (100 + 20) * j, 80 + (30 +20) * i, 100, 30)];
                    label.text = @"程序猿";
                    label.textColor = [UIColor blackColor];
                    label.textAlignment = NSTextAlignmentCenter;
                    label.backgroundColor = [UIColor redColor];
                    [self.window addSubview:label];
             
                }
            }
(2):
        for (int i = 0; i < 9; i++) {
            CGFloat x = 20 + (i / 3) * (80 + 20);
            CGFloat y = 20 + (i % 3) * (50 + 20);
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(x, y, 80, 50)];
            label.text = @"程序猿";
            label.textColor = [UIColor blueColor];
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor redColor];
            [self.window addSubview:label];
            label.tag = i + 100;
            UILabel *label1 = (UILabel *)[self.window viewWithTag:104];
            label1.text = @"赵成浩";
       }

转载于:https://www.cnblogs.com/sharkHZ/p/4984142.html

你可能感兴趣的文章
.net 冒泡排序示例
查看>>
Uva(10330)
查看>>
vlan学习
查看>>
R-Sys.time计算程序运行时间
查看>>
Java类模板
查看>>
【转贴】SAP HANA内存数据库详解
查看>>
二分查找BinarySearch(Java)
查看>>
两种应该掌握的排序方法--------1.shell Sort
查看>>
vuejs动态组件给子组件传递数据
查看>>
javascript constrator and prototype
查看>>
杭电2065(递推)红色病毒
查看>>
No Language-Support in system setting ,Ubuntu
查看>>
spring 实现测试解耦
查看>>
Python学习笔记第二十一周
查看>>
js 获取视频的第一帧
查看>>
各种正则验证
查看>>
C#中IS和AS操作符的区别(转)
查看>>
win7远程桌面连接
查看>>
深入浅出JMS(一)——JMS简单介绍
查看>>
[PTA] 数据结构与算法题目集 6-4 链式表的按序号查找 & 6-5 链式表操作集 & 6-6 带头结点的链式表操作集...
查看>>