UI初级 Label

UILabel的部分常用属性

 1 //TODO:UILabel
 2     CGFloat nameLabelX = 50;
 3     CGFloat nameLabelY = 200;
 4     CGFloat nameLabelW = 80;
 5     CGFloat nameLabelH = 40;
 6     
 7     UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameLabelX, nameLabelY, nameLabelW, nameLabelH)];
 8     nameLabel.backgroundColor = [UIColor cyanColor];
 9     
10     //设置文本显示的字
11     nameLabel.text = @"用户名";
12     
13     //设置文本居中
14     nameLabel.textAlignment = NSTextAlignmentCenter; //居中
15     
16     //将nameLabel添加到window 视图上
17     [self.window addSubview:nameLabel];
18     
19     //创建pswLabel对象,并设置frame
20     UILabel *pswLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameLabelX, nameLabelY + 50, nameLabelW, nameLabelH)];
21     
22     pswLabel.backgroundColor = [UIColor cyanColor];
23     
24     pswLabel.text = @"密码";
25     
26     pswLabel.textAlignment = NSTextAlignmentCenter;
27     
28     [self.window addSubview:pswLabel];
29     
30     //用户名后面的label
31     UILabel *nameBackLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameLabelX + 90, nameLabelY, nameLabelW + 100, nameLabelH)];
32     
33     nameBackLabel.backgroundColor = [UIColor yellowColor];
34     
35     nameBackLabel.text = @"请输入用户名";
36     
37     nameBackLabel.textAlignment = NSTextAlignmentCenter;
38     
39     [self.window addSubview:nameBackLabel];
40     
41     //密码后面的label
42     UILabel *pswBackLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameLabelX + 90, nameLabelY + 50, nameLabelW + 100, nameLabelH)];
43     
44     pswBackLabel.backgroundColor = [UIColor yellowColor];
45     
46     pswBackLabel.text = @"请输入密码";
47     
48     pswBackLabel.textAlignment = NSTextAlignmentCenter;
49     
50     [self.window addSubview:pswBackLabel];

当然还有一些美化的属性代码

//label边角变圆
    pswBackLabel.layer.cornerRadius = 20;
    //边框颜色
    pswBackLabel.layer.borderColor = [UIColor redColor].CGColor;
    //边框宽度
    pswBackLabel.layer.borderWidth = 5;
    //label显示内容的行数 0代表没有限制,其他数几就是几行
    pswBackLabel.numberOfLines = 0;

恩,大致常用的就这些了,还有想加的属性的话可以百度搜,有许多大神会发,学无止境

posted @ 2016-03-16 17:50  _小帅  阅读(193)  评论(0编辑  收藏  举报