UILabl 标签的介绍,属性以及使用

//
//  ZKAppDelegate.m
//  03-UILabelDemo
//

#import "ZKAppDelegate.h"

@implementation ZKAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    //创建UILabel(标签)
    //1.创建UILabel对象
    UILabel *label = [[UILabel alloc]init];
    //2.设置位置
    /**
     *  了解iphone
     iphone 4/4s
     尺寸:3.5英寸
     分辨率:640*960
     实际的点(大小):320*480

     iphone 5/5s
     尺寸:4.0英寸
     分辨率:640*1136
     实际的点:320*568

     iphone6
     尺寸:4.7
     分辨率:750*1334
     实际屏幕的点:(375*667)

     iphone Plus
     尺寸:5.5
     分辨率:1080*1920
     实际:(540*960):

     怎么设置标签的位置
     (需要设置的标签左上角的坐标以及大小(长,宽)
     注意:控件的形状都是矩形的。

     为什么要设置左上角的坐标
     因为屏幕的坐标原点是屏幕的左上角

     怎么实际的设置?
     通过oc的结构体CGRect(位置) CGSize(大小) CGPoint(坐标)
     */
    CGPoint point = {0,0};
    CGSize size = {100,40};
    CGRect rect = {point,size};

//    CGRect rect1 = CGRectMake(2, 44, 30, 20);
//    CGPoint point1 = CGPointMake(3, 4);
    //设置标签的位置
    label.frame = rect;
    //3.显示(加载)
    [self.window addSubview:label];

    //4.设置显示内容
    label.text = @"千锋教育";

    //5.设置标签背景
    label.backgroundColor = [UIColor grayColor];

    //6.去掉状态栏
    //6.1
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    //6.2
    //到plist里面设置一些属性
    //View controller-based status bar appearance  设置成NO
    //Status bar is initially hidden  设置成YES

    //相关的属性
    //创建一个标签
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 100, 40)];

    //1.背景颜色
    //两种:1.通过UIColor类封装的一些简单颜色方法。
    //2.通过一个方法,自己配置颜色(RGB(红,绿,蓝,透明度)国际标准)
    //注意:1.四个参数取值范围[0,1] 2.里面的值不要写整数,要写浮点数。 3.前三个参数的表示方式:[0,255]/255.  全1是白色  全0是黑色
    //label1.backgroundColor = [UIColor yellowColor];
    label1.backgroundColor = [UIColor colorWithRed:63./255. green:117./255. blue:1./255. alpha:1];

    //3.设置字体
    label1.text = @"iOS培训";

    //4.设置字体颜色
    label1.textColor = [UIColor redColor];

    //5.字体大小
    //5.1普通的
    label1.font = [UIFont systemFontOfSize:20];
    //5.2设置加粗的
    label1.font = [UIFont boldSystemFontOfSize:30];

    //6.字体的样式
    label1.font = [UIFont fontWithName:@"menlo" size:15];
    //6.2查看字体
    NSLog(@"%@",[UIFont familyNames]);

    //7.字体的位置
    label1.textAlignment = NSTextAlignmentCenter;

    //8.阴影
    //8.1阴影颜色
    label1.shadowColor = [UIColor blueColor];
    //8.2阴影大小
    label1.shadowOffset = CGSizeMake(5, 5);

    [self.window addSubview:label1];

    //9.文字的自适应
    UILabel *label2 = [[UILabel alloc]init];

    label2.text = @"我们在1438班学习我们在1438班学习我们在1438班学习我们在1438班学习我们在1438班学习我们在1438班学习我们在1438班学习我们在1438班学习我们在1438班学习我们在1438班学习我们在1438班学习";

    [self.window addSubview:label2];

    label2.backgroundColor = [UIColor grayColor];

    //9.1长,宽都是固定的。当width或height为0的时候代表无限制
    label2.frame = CGRectMake(10, 200, 200, 0);

    //9.2行数 默认是1,等于0时,代表无限行(任意行)
    label2.numberOfLines = 0;

    //9.3.文字有多大,范围就有多大
    [label2 sizeToFit];

    //获取label的高度
    //注意:获取值的大小要与开始创建时给定的大小保持一致
     CGSize size1 = [label2 sizeThatFits:CGSizeMake(200, 0)];

    NSLog(@"%lf",size1.height);

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end