```
? ? NSString * showText = @"你的快遞包裹到了,簽收人:張三,電話:13987654321,送貨員:李四,電話:15888888888,收件地址:火星";
? ? UILabel*testTapLabel = [[UILabelalloc]initWithFrame:CGRectMake(0,100,self.view.frame.size.width,500)];
? ? testTapLabel.numberOfLines=2;
? ? testTapLabel.attributedText = [self getAttributeWith:@[@"13987654321",@"15888888888"] string:showText orginFont:12 orginColor:[UIColor darkGrayColor] attributeFont:12 attributeColor:[UIColor blueColor]]; ? ?[testTapLabelyb_addAttributeTapActionWithStrings:@[@"13987654321",@"15888888888"]tapClicked:^(UILabel*label,NSString*string,NSRangerange,NSIntegerindex) {
?? ? ? ?NSString* message = [NSStringstringWithFormat:@"點(diǎn)擊了\"%@\"字符\nrange:%@\n在數(shù)組中是第%ld個",string,NSStringFromRange(range),index +1];
? ? ? ? YBAlertShow(message,@"知道了");
? ? }];
? ? [self.viewaddSubview:testTapLabel];
}
- (NSAttributedString*)getAttributeWith:(id)sender
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? string:(NSString*)string
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? orginFont:(CGFloat)orginFont
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? orginColor:(UIColor*)orginColor
?? ? ? ? ? ? ? ? ? ? ? ? ? attributeFont:(CGFloat)attributeFont
? ? ? ? ? ? ? ? ? ? ? ? ? attributeColor:(UIColor*)attributeColor
{
? ? __block? NSMutableAttributedString *totalStr = [[NSMutableAttributedString alloc] initWithString:string];
? ? [totalStraddAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:orginFont] range:NSMakeRange(0, string.length)];
? ? [totalStraddAttribute:NSForegroundColorAttributeNamevalue:orginColorrange:NSMakeRange(0, string.length)];
? ? NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
? ? [paragraphStylesetLineSpacing:5.0f];//設(shè)置行間距
? ? [paragraphStylesetLineBreakMode:NSLineBreakByTruncatingTail];
? ? [paragraphStylesetAlignment:NSTextAlignmentLeft];
? ? [paragraphStylesetLineBreakMode:NSLineBreakByCharWrapping];
? ? [totalStraddAttribute:NSParagraphStyleAttributeNamevalue:paragraphStylerange:NSMakeRange(0, [totalStrlength])];
? ? if([senderisKindOfClass:[NSArrayclass]]) {
? ? ? ? __blockNSString*oringinStr = string;
? ? ? ? __weaktypeof(self) weakSelf =self;
? ? ? ? [senderenumerateObjectsUsingBlock:^(NSString*? _Nonnullstr,NSUIntegeridx,BOOL*_Nonnullstop) {
? ? ? ? ? ? NSRangerange = [oringinStrrangeOfString:str];
? ? ? ? ? ? [totalStraddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:attributeFont]range:range];
? ? ? ? ? ? [totalStraddAttribute:NSForegroundColorAttributeNamevalue:attributeColorrange:range];
? ? ? ? ? ? oringinStr = [oringinStrstringByReplacingCharactersInRange:rangewithString:[weakSelfgetStringWithRange:range]];
? ? ? ? }];
? ? }elseif([senderisKindOfClass:[NSStringclass]]) {
? ? ? ? NSRangerange = [stringrangeOfString:sender];
? ? ? ? [totalStraddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:attributeFont]range:range];
? ? ? ? [totalStraddAttribute:NSForegroundColorAttributeNamevalue:attributeColorrange:range];
? ? }
? ? returntotalStr;
}
- (NSString*)getStringWithRange:(NSRange)range
{
? ? NSMutableString *string = [NSMutableString string];
? ? for(inti =0; i < range.length; i++) {
? ? ? ? [stringappendString:@" "];
? ? }
? ? returnstring;
}
```