str 为某一字符串
NSString *str = RowArr[indexPath.row];
NSRange allRange = NSMakeRange(0, str.length);
NSRange range = NSMakeRange(0, 3);
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:str];
UIFont *boldSystemFont = [UIFont boldSystemFontOfSize:15];
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL);
[attributedString addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)font range:NSMakeRange(0, str.length)];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHex:0xD94448] range:allRange];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHex:0X5E5E5E] range:range];
cell.orderInfoLabel.delegate = self;
[cell.orderInfoLabel addLinkToURL:[NSURL URLWithString:@"买家"] withRange:NSMakeRange(3, str.length)];
cell.orderInfoLabel.attributedText = attributedString;
事件点击事件的方法
#pragma mark - TTTAttributedLabelDelegate
- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Message" bundle:nil];
BubbleChatViewController *bubbleChatVC = [storyboard instantiateViewControllerWithIdentifier:@"BubbleChatVC"];
NSString *str = [[label.text componentsSeparatedByString:@":"] objectAtIndex:0];
if ([str isEqualToString:@"买家"]) {
bubbleChatVC.userID = self.order.buyer.userID;
} else {
bubbleChatVC.userID = self.order.opus.opusAuthor.userID;
}
[self.navigationController pushViewController:bubbleChatVC animated:YES];
}
本文详细介绍了如何在iOS应用中利用Objective-C与Swift编写代码实现内链跳转功能,包括创建链接、设置点击事件以及跳转到指定页面的过程。通过实例演示,帮助开发者掌握iOS应用内的页面跳转技巧。

1617

被折叠的 条评论
为什么被折叠?



