码迷,mamicode.com
首页 > 其他好文 > 详细

一 UI基本的用法

时间:2015-05-12 01:40:04      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

1. UIView的基本用法

    //打印屏幕的宽和高
    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    NSLog(@"%f, %f", screenBounds.size.width, screenBounds.size.height);
    
    //创建一个UIView
    //UIView表示一个矩形区域
    UIView *v1 = [[UIView alloc] init];
    //1.确定大小
    CGRect rect = CGRectMake(0, 0, 100, 100);
    v1.frame = rect;
    
    //2.确定颜色
    v1.backgroundColor = [UIColor redColor];
    
    //3.添加到窗口
    [self.window addSubview:v1];
    
    //以下两句创建UIView可以简写为一句,用initWithFrame:CGRectMake
    //UIView *v4 = [[UIView alloc] init];
    //v4.frame = CGRectMake(320 - 100, 480 - 100, 100, 100);
    UIView *v4 = [[UIView alloc] initWithFrame:CGRectMake(320 - 100, 480 - 100, 100, 100)];
    v4.backgroundColor = [UIColor yellowColor];
    [self.window addSubview:v4];

2. UILable基本用法

    //标签控件,主要用来做信息提醒
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(10, 20, 300, 30);
    //label.backgroundColor = [UIColor blackColor];
    
    //设置显示内容
    label.text = @"Sent";
    
    //设置字体和字体大小
    //1.获取当前系统所有支持的字体
    NSArray *allFont = [UIFont familyNames];
    NSLog(@"allFont = %@", allFont);

//2.选择使用其中一个字体,系统默认字体大小为17 UIFont *font = [UIFont fontWithName:@"Party LET" size:40];
//3.将字体使用到label上 label.font = font; //设置字体颜色 label.textColor = [UIColor redColor]; //对齐方式 //NSTextAlignmentLeft 左对齐(默认) //NSTextAlignmentRight 右对齐 //NSTextAlignmentCenter 居中 label.textAlignment = NSTextAlignmentCenter; //设置文字阴影 //1.阴影大小 //宽高可以理解为偏移量,是相对于label的第一个字的偏移 // width height // + + 右下角 // + - 右上角 // - + 左下角 // - - 左上角 // + 0 右边 // - 0 左边 // 0 + 下边 // 0 - 上边 CGSize offset = CGSizeMake(0, -5); label.shadowOffset = offset; //2.阴影颜色 label.shadowColor = [UIColor brownColor]; //设置行数,默认为1行 label.numberOfLines = 10 /*行数,如果 == 0 表示任意多行*/; //自动调整字体,以显示完所有内容,YES为自动调整 label.adjustsFontSizeToFitWidth = NO; [self.window addSubview:label];

 

一 UI基本的用法

标签:

原文地址:http://www.cnblogs.com/wlsky/p/4496022.html

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