ios UILabel简单使用方法

UILabel简单使用方法:

    

//创建UILabel
UILabel *label = [ [UILabel alloc] initWithFrame: CGRectMake(20, 20, 200, 200)];

//设置文本
label.text = @"文本内容";

//设置背景色
label.backgroundColor = [UIColor blackColor];

//设置字体大小
label.font = [UIFont systemFontOfSize: 15];

//设置字体粗体 和 大小
label.font = [UIFont boldSystemFontOfSize: 15];

//设置字体类型 和 大小
label.font = [UIFont fontWithName: @Arial size: 20];

//设置字体大小适应label宽度
label.adjustsFontSizeToFitWidth = YES;

//设置文字颜色
label.textColor = [UIColor redColor];

//设置文本对齐方式
label.textAlignment = UITextAlignmentCenter;
label.textAlignment = UITextAlignmentRight;

//设置阴影
label.shadowColor = [UIColor redColor];
label.shadowOffset  = CGSizeMake(1.0, 1.0);

//设置高亮
label.highlighted = YES;
label.highlightedTextColor = [UIColor orangeColor];

//设置text是否可变,  默认为YES
label.enabled = NO;

//设置文本过长时的显示格式
label.lineBreakMode = UILineBreakModeMiddleTruncation;   //截去中间

猜你喜欢

转载自2914905399.iteye.com/blog/2299835