
UILabel.png
----- UILabel -----
//1 创建Label
UILabel *namelabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
//2 设置属性
//设置文字
namelabel.text = @"姓名";
//设置背景颜色
namelabel.backgroundColor = [UIColor whiteColor];
//设置内容对齐方式
namelabel.textAlignment = NSTextAlignmentCenter;
//设置内容字体大小
//namelabel.font = [UIFont systemFontOfSize:20];
namelabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
//设置文字超出, 换行显示
namelabel.lineBreakMode = NSLineBreakByCharWrapping;
namelabel.numberOfLines = 0;
//设置Label圆角
namelabel.layer.borderWidth = 1;
namelabel.layer.cornerRadius = 8;
namelabel.layer.masksToBounds = YES;
//设置文字效果
//阴影效果
namelabel.shadowColor = [UIColor colorWithRed:0.203 green:0.260 blue:0.571 alpha:0.462];
//阴影位置
namelabel.shadowOffset = CGSizeMake(5, 5);// (x, y)
//设置文字角度
namelabel.transform = CGAffineTransformMakeRotation(0.2);
//添加富文本
//1 声明富文本
NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:@"富文本文字+ 测试换行文字文字文字文字文字文字"];
//2 设置富文本内容样式
//2.1 字体大小
//参数一: 修改的属性 参数二: 类型的具体值 参数三: 修改的区间
[attributeStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:40] range:NSMakeRange(0, 3)];
//2.2 设置空心字
[attributeStr addAttribute:NSStrokeWidthAttributeName value:@2 range:NSMakeRange(0, 4)];
//2.3 设置空心字颜色
[attributeStr addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 4)];
//3 为label指定富文本对象(需要放置在富文本样式后面)
namelabel.attributedText = attributeStr;
//namelabel.backgroundColor = [UIColor colorWithRed:0.792 green:1.000 blue:0.814 alpha:1.000];
//3 添加到视图
[self.view addSubview:namelabel];