gpt4 book ai didi

ios - 文本上的操作标签

转载 作者:行者123 更新时间:2023-11-28 06:13:46 27 4
gpt4 key购买 nike

我有一个 Xcode 项目,我想在其中为类似于提及 (@) 和主题标签 (#) 标签的名称制作一个 Action 标签,其中它是粗体的,我可以按下它,它会将我发送到另一个 View Controller .我已经四处搜索了这个,只找到了用于提及和标签的 cocoa pod 。 我该如何实现?

示例:“Mark Smith 喜欢你的照片。”然后我就可以按“Mark Smith”,它会将我转到他的个人资料。

最佳答案

也许你可以用 UITextView 替换 UILabel,运行这个简单的代码:

`func addLinkLabel() {
let textView = UITextView.init(frame: CGRect.init(x: 10, y: 150, width: 400, height: 100))
self.view.addSubview(textView)

let attributedString = NSMutableAttributedString.init(string: "Touch me,you'll be sent to another ViewController.")
attributedString.addAttribute(NSLinkAttributeName, value: "aa", range: NSRange.init(location: 0, length: 8))
textView.attributedText = attributedString
textView.font = UIFont.systemFont(ofSize: 17)
textView.linkTextAttributes = [NSFontAttributeName:UIFont.boldSystemFont(ofSize: 20),
NSForegroundColorAttributeName:UIColor.red]
textView.isEditable = false
textView.delegate = self;

}

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
if String(describing: URL) == "aa" {
print("Here we go...")
self.navigationController?.pushViewController(SecondViewController(), animated: true)
return true
}
return false
}

`

关于ios - 文本上的操作标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45725214/

27 4 0