实用、好用、便捷的
attributedText
self.timeLabel.attributedText = [self getAttWithTitle:@"周一至周六 8:00至20:00" img:[UIImage imageNamed:@"lovecar_nearby_time"]];
/// 获取文字和图片的组合
/// @param title 文字
/// @param img 图片
- (NSAttributedString *)getAttWithTitle:(NSString *)title img:(UIImage *)img {
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.headIndent = 16;
paragraphStyle.lineSpacing = 3;
NSMutableAttributedString *att = [[NSMutableAttributedString alloc] init];
NSTextAttachment *imgAtt = [[NSTextAttachment alloc] init];
imgAtt.image = img;
imgAtt.bounds = CGRectMake(0, -4, 16, 16);
[att appendAttributedString:[NSAttributedString attributedStringWithAttachment:imgAtt]];
[att appendAttributedString:[[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:11],NSForegroundColorAttributeName : RGBA(153, 153, 153, 1)}]];
[att addAttributes:@{NSParagraphStyleAttributeName : paragraphStyle} range:NSMakeRange(0, att.length)];
return att;
}