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]]; app
//根據文字的多少計算label寬度 NSDictionary *labDic = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:18]}; CGSize size=[lab.text sizeWithAttributes:labDic];
[lab setFrame:CGRectMake(0, 0, size.width, 20)];