设置步骤
(1).
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 150)];
(2).
label.backgroundColor = [UIColor yellowColor];
(3).
[self.window addSubview:label];
(4).
[label release];
(5).设置文本内容
label.text = @"李牧燃你是谁??"
(6).对文本操作
a:文本内容的颜色
label.textColor = [UIColor redColor];
b:文本对齐方式
label.textAlignment = NSTextAlignmentCenter;
注意:默认是居左
c:字体大小
label.font = [UIFont systemFontOfSize:20];
d:设置行数
label.numberOfLines = 3;
[label sizeToFit];
注意:这两行代码配合使用可以让文本自己去适应lable的尺寸,显示全部内容
默认是一行
e:断行模式
label.lineBreakMode = NSLineBreakByTruncatingHead;
f:阴影大小
label.shadowOffset = CGSizeMake(10, 1);
g:阴影颜色
label.shadowColor = [UIColor grayColor];
h:设置边框
label.layer.borderWidth = 1;
h(1):设置边框颜色
i:设置圆角
label.layer.cornerRadius = 75;(可能还会看到边框(圆)意外的部分)
label.layer.masksToBounds = YES;(可以去掉这些不分)
j:改变尺寸
label.frame = CGRectMake(100, 100, 200, 200);
变量名.layer.borderColor = [UIColor grayColor].CGColor;
可以修改视图的位置
label.center = CGPointMake(100 + 75, 100 + 75);