码迷,mamicode.com
首页 > Windows程序 > 详细

进击的UI-----------------UIWindow&UIView&UILabel

时间:2015-11-21 18:13:40      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

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 = @"赵成浩";
       }

进击的UI-----------------UIWindow&UIView&UILabel

标签:

原文地址:http://www.cnblogs.com/sharkHZ/p/4984142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!