简体   繁体   English

如何制作包含可点击链接的可滚动标签?

[英]How can I make a scrollable label that contains clickable links?

In my app I've created a small RSS feed reader that shows the titles of the news. 在我的应用程序中,我创建了一个小型的RSS feed阅读器,用于显示新闻标题。 I've simply put the titles in a single string and I'm showing them in a scrolling MarqueeLabel . 我只是将标题放在单个字符串中,并在滚动的MarqueeLabel中显示它们。 I'd like to make the titles clickable to show the linked news and I've tried to do so following this answer , but the string is not interactable at all, even if it is highlighted as a hyperlink. 我想使标题可单击以显示链接的新闻,并且我尝试按照此答案进行操作 ,但是即使该字符串突出显示为超链接,该字符串也完全不可交互。

Is there an easy way to make it work? 有没有简单的方法可以使其正常工作? I've tried to look if there are libraries that combine both the scrolling and the linking functionalities, but I couldn't find any. 我试图查看是否有结合了滚动功能和链接功能的库,但找不到。

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
[marqueeLabel addGestureRecognizer:tapGesture];

-(void)handleTap:(UITapGestureRecognizer *)gesture{
    MarqueeLabel *marqueeLabel =  (MarqueeLabel*) [gesture view];
    NSLog(@"Clicked Link would be %@",marqueeLabel.text);

}

NB:Just add UITapGestureRecognizer to your desired label and handle it 注意:只需将UITapGestureRecognizer添加到所需标签并进行处理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM