ios - 在 UILabel 中显示可点击的 URL 和图标

标签 ios uilabel nstextattachment tttattributedlabel

我在我的应用程序中使用 TTTAtributedLabel 作为 URL 和电话号码。一切正常,但问题是现在我需要在 UILabel 中显示图标。在我使用下面给出的代码之前。但是由于 TTTAtributedLabel 的使用,现在 NSTextAttachment 没有显示在 TTTAtributedLabel 中。 TTTAtributedLabel 不支持附件。那么在 UILabel 中支持 URL、电话号码和图标有什么想法吗?


现在我决定在 TTTAttributedLabel 中显示 unicode 图像。它工作正常。

最佳答案

最好使用 UITextView 并设置 textView 的数据检测器类型。

textView.dataDetectorTypes = UIDataDetectorTypeAddress | UIDataDetectorTypeLink |     UIDataDetectorTypePhoneNumber;

当 TextView 中的链接或 url 被选中时,有一个委托(delegate)方法被调用

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);

这会为您提供在 TextView 中点击的 URL,您可以执行所需的操作。

关于ios - 在 UILabel 中显示可点击的 URL 和图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27716967/

相关文章:

swift - 用于分段控件的 UITesting Swift

ios - 使用 NSTextAttachment 为 NSAttributedString 设置截尾的垂直对齐

ios - 选择节标题时显示行

objective-c - iOS:UITableViewCell 中的 UIButton 和 UILabel

ios - 如何动态为按钮分配方法

ios - 使用 AudioKit 锁定屏幕中的音频控件

ios - 通过增加标签计数来添加图像

objective-c - 带有 UILabel subview 缓存问题的 UITableViewCell

ios - 用 NSTextAttachment 替换 UILabel 中的表情符号 - 无法将纯文本表示设置回常规表情符号以进行复制/粘贴

ios - 更改 NSTextAttachment 图像的大小?