先来说下 UILabel 设置高亮文字和图片,看下效果图,当当当👇
image.png没啥可说的,直接贴代码吧
// 描述文字属性调整
UIFont *detailFont = [UIFont systemFontOfSize:is320 ? 14 : 16];
UIColor *detailColor = [UIColor mmsRGBColorFromHexString:@"#dddddd" alpha:1];
NSMutableParagraphStyle *detailStyle = [[NSMutableParagraphStyle alloc] init];
[detailStyle setParagraphStyle:[[NSParagraphStyle alloc] init]];
detailStyle.lineSpacing = is320 ? 7 : 8;
NSDictionary *detailAttr = @{NSFontAttributeName : detailFont,
NSForegroundColorAttributeName : detailColor,
NSParagraphStyleAttributeName : detailStyle};
// detail1
NSString *detail1 = @"1、点击“ 识别图 ”,下载或分享AR识别图到其他电子设备上打开";
NSMutableAttributedString *detail1AttrStr = [[NSMutableAttributedString alloc] initWithString:detail1];
[detail1AttrStr addAttributes:detailAttr range:NSMakeRange(0, detail1AttrStr.length)];
// 加亮文字处理
UIColor *lightColor = [UIColor mmsRGBColorFromHexString:@"#3388ff" alpha:1];
NSRange lightRange = [detail1 rangeOfString:@"“ 识别图 ”"];
NSRange linkRange = NSMakeRange(lightRange.location + 1, lightRange.length - 2);
[detail1AttrStr addAttribute:NSForegroundColorAttributeName value:lightColor range:linkRange];
//加亮图片
UIImage *iconImg = [MISImageSearchBundle imageNamed:@"ar_recognize_blue"];
NSTextAttachment *icon = [[NSTextAttachment alloc] init];
icon.image = iconImg;
CGFloat iconWidth = is320 ? 13 : 14;
icon.bounds = CGRectMake(0, -1, iconWidth, iconWidth);
NSAttributedString *iconAttrStr = [NSAttributedString attributedStringWithAttachment:icon];
[detail1AttrStr replaceCharactersInRange:NSMakeRange(lightRange.location+2, 0) withAttributedString:iconAttrStr];
self.detailLbl1.attributedText = detail1AttrStr;
嗯嗯,没什么技术难度,接下来的可点击怎么做呐🤔️
首先我这个方法是需要xib的,还不晓得不用xib咋做呀~~~
我们只需要来个xib,然后拖出来一个 UILabel,把 UILabel 需要现实的文字写好,然后~~~你只需要再拖出来一个 UIButton ,把 UIButton 刚刚好放在需要点击的文字上,然后把约束加好,如下所示👇
image.png完成啦,哈哈哈,是不是很简单,不要打我🤨
网友评论