iOS UILanel 一些小实用

UILabel *lab=[[UILabel alloc]initWithFrame:self.view.bounds];

//合并
lab.text=[NSString stringWithFormat:@"%@%@",@"coach: ","coache"];

//圆形
lab.layer.cornerRadius=num1.bounds.size.width/2;
lab.layer.masksToBounds=YES;

//换行,高度要足够才能换行
lab.lineBreakMode = NSLineBreakByWordWrapping;
lab.numberOfLines = 0;

//边框
lab.layer.borderColor = [UIColor colorWithRed:236.0f/255.0f green:235.0f/255.0f blue:240.0f/255.0f alpha:1].CGColor;//颜色
lab.layer.borderWidth = 3.0f;//设置边框粗细
lab.layer.masksToBounds = YES;

lab.textAlignment =  NSTextAlignmentCenter;//居中
lab.textAlignment = NSTextAlignmentLeft;//靠左
lab.textAlignment = NSTextAlignmentRight;//靠右

[lab setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]]; 

//根据文字的多少计算label宽度

NSDictionary *labDic = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:18]};
CGSize size=[lab.text sizeWithAttributes:labDic]; 
[lab setFrame:CGRectMake(
0, 0, size.width, 20)];
原文地址:https://www.cnblogs.com/sheer-code/p/10871429.html