【问题标题】:Make UILabel Text Clickable使 UILabel 文本可点击
【发布时间】:2013-12-26 20:56:35
【问题描述】:

我想让UILabel 上的某些特定文本可点击,例如:@"Lorem Ipsum is simply dummy text of the printing bla bla"

在这个字符串中"Ipsum,dummy,printing" 应该是可点击的,并且它的颜色也应该改变。我用TTTAttributedLabel(自定义类)试过这个,但它只是改变颜色。

请给我任何有用的建议。

【问题讨论】:

  • 是的,您可以使用自定义按钮并在 touchupainside 上更改按钮的背景。
  • 这个我没用过,你可以试试看。maniacdev.com/2012/12/…

标签: ios objective-c uilabel tttattributedlabel


【解决方案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);
}

您的标签将如下所示:

【讨论】:

    猜你喜欢
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 2013-11-20
    相关资源
    最近更新 更多