效果图:
Snip20160701_1.png注意:其中红色的整体是一个UILabel,但是需求是人的名字的字体颜色是不一样的!!!
- (void)setModel:(_DiagnoseDetailSuccessModel *)model{
_model = model;
// 要截取的字符串
NSString * patientContent = [NSString stringWithFormat:@"%@ %@ %@岁",model.name,model.genderName,model.age];
NSMutableAttributedString * attributeString = [[NSMutableAttributedString alloc] initWithString:patientContent];
// 此处是截取的范围
NSRange range = [patientContent rangeOfString:model.name];
[attributeString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:15] range:range];
// 此处应注意是attributedText,而不是text
_patientLabel.attributedText = attributeString;
_timeLabel.text = model.create_time;
_stateLabel.text = model.state;
}
网友评论