UITextView *upText = [[UITextView alloc] init];
upText.font = [UIFont systemFontOfSize:14.f];
upText.backgroundColor = [UIColor clearColor];
upText.textColor = [UIColor whiteColor];
upText.textAlignment = NSTextAlignmentLeft;
upText.text = LocalString(@"1.Turn on your Robot\n2.Unlock the keyboard;\n3.Press the button for 5seconds,till the LED light flashing(fast)\n4.Press the button");
[_oneModelImage addSubview:upText];
[upText mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(yAutoFit(200), yAutoFit(100)));
make.centerX.equalTo(self.oneModelImage.mas_centerX);
make.top.mas_equalTo(upImage.mas_bottom).offset(yAutoFit(5));
}];
_oneModelImage.layer.borderWidth = 1.0;
_oneModelImage.layer.borderColor = [UIColor whiteColor].CGColor;
_oneModelImage.layer.cornerRadius = 10.f/HScale;
//2.初始化富文本对象
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:upText.text];
//2.1修改富文本中的不同文字的样式
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, attributedString.length)];//字体颜色
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, attributedString.length)];//字体大小
//3.初始化NSTextAttachment对象
NSTextAttachment *attchmentOne = [[NSTextAttachment alloc]init];
attchmentOne.bounds = CGRectMake(0, 0,yAutoFit(20), yAutoFit(10));//设置frame
attchmentOne.image = [UIImage imageNamed:@"img_model1_help_up_text"];//设置图片
//4.创建带有图片的富文本
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:(NSTextAttachment *)(attchmentOne)];
[attributedString insertAttributedString:string atIndex:63];//插入到第几个下标
//[attributedString appendAttributedString:string]; //添加到尾部
//5.用label的attributedText属性来使用富文本
upText.attributedText = attributedString;