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

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

}

时间: 2024-10-27 11:15:08

进击的UI-----------------UIWindow&UIView&UILabel的相关文章

iOS开发-UI (一)补充 UIWindow UIView UIlabel

之前忘了把这些整理出来,现在补充一下,应该放在前面学习的 知识点: 1.UI的初步认识 2.UIWindow 3.UIView 4.UIlabel ======================== UI的初步认识 1.什么是UI(*) UI即User Interface(用户界面)的简称.UI设计则是指对软 件的人机交互.操作逻辑.界面美观的整体设计.好的UI设 计不仅是让软件变得有个性有品味,还要让软件的操作变得 舒适.简单.自由.充分体现软件的定位和特点. 2.第一个UI工程 1)UI工程的

UI 常用方法总结之--- UIWindow UIView (不断更新中)

 UIWindow (UIView) 1.创建一个uiwindow对象 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 2.backgroundColor 背景颜色 3.- (void)makeKeyAndVisible; eg: [self.window makeKeyAndVisible]; 设置这个window为主windows,并使其可见 4.rootViewController

第一章 UI实战开发 UIWindow UIView

UI 即:用户界面   UIWindow的使用 用法 对UIWindow 进行初始化 IOS 程序的入口 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { (self.window = [[UIWindow alloc] init ];//WithFrame:[UIScreen mainScreen].bounds];//创建w

UI第一讲.UIWindow UIView UILable 的基本使用

一.UIWindow 二.UIView 三.UILable

UI 初识UIView

1.UIWindow App靠window来呈现内容,?个程序?般只创建?个window. 通常window的??(frame)与屏幕(UIScreen)???致. ?例代码如下: self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; _window.backgroundColor = [UIColor whiteColor];    // 视图的添加写在这里    [_window makeKe

IOS开发UI基础UIView

主要介绍下UIView得基本概念和一些属性的介绍至于属性的用户后面会由详细的介绍 -.UIView基本概念 1.什么是控件? 屏幕上所有的UI元素都叫做控件 (也有很多书中叫做视图 组件) 比如 按钮(UIButton) 文本(UILabel)都是控件 控件的共同属性有哪些? 尺寸 位置 背景色 ........... 苹果将控件的共同属性都抽取到父类UIView中 所有的控件最终都继承自UIView中 UIBUtton UIView都继承自UIView 父控件.子控件 每个控件都是个容器 能够

iOS开发UI—UIWindow介绍

一.简单介绍 UIWindow是一种特殊的UIView,通常在一个app中只会有一个UIWindow iOS程序启动完毕后,创建的第一个视图控件就是UIWindow,接着创建控制器的view,最后将控制器的view添加到UIWindow上,于是控制器的view就显示在屏幕上了 一个iOS程序之所以能显示到屏幕上,完全是因为它有UIWindow.也就说,没有UIWindow,就看不见任何UI界面 补充:UIWindow是创建的第一个视图控件(创建的第一个对象是UIapplication)如下图:

UI开发----UIView和UILable

//  Created By 郭仔  2015年04月10日17:48:32 今天还要买两张票,周天回家周天在回来!不管什么事,请记住:  有我在!!! 祝:天佑郭家!!! ========================================================================== Window窗口: window是窗?口,每个app都需要借助window将内容展现给?用户看. 在iOS中,使?用UIWindow类来表?示窗?口,通常?一个应?用程序只创建

UI基础UIView常见属性及方法

1.NSBundle 1> 一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹 2> 利用mainBundle就可以访问软件资源包中的任何资源 3> 模拟器应用程序的安装路径 /Users/aplle/资源库/Application Support/iPhone Simulator/7.1/Applications 2.UIImageView和UIButton 1> 使用场合 * UIImageView: 如果仅仅是显示图片,不需要监听图片的点击 * UIB