我希望点击UILabel
上的某些特定文字,例如:@"Lorem Ipsum is simply dummy text of the printing bla bla"
在此字符串中"Ipsum,dummy,printing"
应该是可点击的,并且其颜色也应该更改。我用TTTAttributedLabel
(自定义类)尝试了这个,但它只改变了颜色。
请给我任何有用的建议。
答案 0 :(得分:1)
现在不要使用Three20
库。使用基于RTLabel
https://github.com/honcheng/RTLabel
RTLabel *html = [[RTLabel alloc]init];
html.delegate = self;
strHTML.text = [NSString stringWithFormat:@" <font face=TrebuchetMS size=%i>Unlimited searches of ICD-10-CM Search apps for iPad, iPhone, and iTouch.\n<a href='%@'><font color=#0094fa>%@</font></a> per month</font>", DESC_FONT, @"m", @"$2.99"];
html.frame = CGRectMake(0, 0, TEXT_WIDTH, ROW_HEIGHT);
[html setLineSpacing:5];
[html setLineBreakMode:RTTextLineBreakModeWordWrapping];
[html setBackgroundColor:[UIColor clearColor]];
[html setText:strHTML];
[html setUserInteractionEnabled:YES];
[self.view addSubview:html];
这是它的委托方法:
- (void)rtLabel:(id)rtLabel didSelectLinkWithURL:(NSURL*)url
{
NSLog(@"%@", url);
}
您的标签将如下所示: