UILable 即文字显示便签
初始化方法
UILabel *label = [[UILable alloc]init];
UILabel *label = [UIlable New];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 200)];
常用属性
@property(nullable, nonatomic,copy) NSString *text; // default is nil 默认为nil,text 即标签显示的内容,例如 label.text = @"天王盖地虎";
@property(null_resettable, nonatomic,strong) UIFont *font; // -default is nil (system font 17 plain) 默认nil ,不设置会跟随你的高度,font 即显示内容字体的大小 例如 label.font = [ UIFont systemFontOfSize:20 ]; 则是设置字体为系统字体20号字
@property(null_resettable, nonatomic,strong) UIColor *textColor; //标签文字颜色,例如 label.textColor =[UIColor whiteColor]; @property(nonatomic) NSTextAlignment textAlignment; //标签的对齐方式,默认左对齐,可选左,中,右
label.textAlignment = NSTextAlignmentCenter; //居中
label.textAlignment = NSTextAlignmentLeft; //左对齐
label.textAlignment = NSTextAlignmentRight;//右对齐
@property(nonatomic) NSInteger numberOfLines;//标签文字的行数,默认为一行,设置为0 则不限制 例如 lab.numberOfLines = 0; label.numberOfLines = 2;
创建一个 Hello World 标签并添加到视图
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50,100, 300, 20)];
label.text= @"Hello World";
[self.view addSubview:label];
image.png
设置文字居中,字体颜色为白色,字体大小为10号
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont systemFontOfSize:10];
label.textColor = [UIColor whiteColor];
image.png
网友评论