iOS UI学习笔记(三)UIlable

简单易懂,通过代码练习可以熟悉大部分内容

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    //lable是标签,作用是呈现文字内容,如果UIView有自己的初始化方法就用自己的,没有就用父类的。
    UILabel *myLable = [[UILabel alloc]initWithFrame:CGRectMake(30, 100, 100, 200)];
    //设置背景颜色
    [myLable setBackgroundColor:[UIColor blackColor]];
    [self.window addSubview:myLable];
    //为lable添加文字内容
    myLable.text = @"I am VIP";
    //设置lable的显示行数,前提是高度足够。当行数设置为0时,文字会根据高度自动换行。
    myLable.numberOfLines=0;
    //设置文字颜色
    NSLog(@"%@",myLable.font);
    myLable.textColor = [UIColor blueColor];
    //设置字体大小
    myLable.font= [UIFont systemFontOfSize:20];
    //得到系统提供的所有字体
    NSArray *fontArray = [UIFont familyNames];
    NSLog(@"----%@",fontArray);
    //设置字体类型和大小
    myLable.font = [UIFont fontWithName:@"DIN Condensed" size:25];
    //设置lable的拆行方式
//    myLable.lineBreakMode = NSLineBreakByTruncatingMiddle;
    myLable.lineBreakMode = NSLineBreakByCharWrapping;
    //设置文字对齐方式(枚举值,有多种类型)
    myLable.textAlignment = NSTextAlignmentCenter;
    myLable.shadowColor = [UIColor magentaColor];
    myLable.shadowOffset = CGSizeMake(2, 1);
    self.window.backgroundColor = [UIColor whiteColor];
    //显示图片的控件 相框
    UIImageView *myImageView= [[UIImageView alloc]initWithFrame:CGRectMake(150, 100, 300, 300)];
    [self.window addSubview:myImageView];
    //得到资源图片
    UIImage *myImage = [UIImage imageNamed:@"321.jpg"];
    //添加图片到相框
    myImageView.image = myImage;
    [self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    [self.window makeKeyAndVisible];

    return YES;
}


你可能感兴趣的:(ios,UI,UILabel)