【发布时间】:2018-06-11 08:55:42
【问题描述】:
我必须确保我可以点击“隐私”一词才能打开网页链接。我尝试了我发现的建议,但它们是旧东西,它们似乎不再起作用..我不知道如何解决问题
private lazy var firstTermDescriptionLabel: UILabel = {
let label = UILabel(frame: .zero)
let firstTermsMessage = "I Agree to the License Terms and Privacy Policy"
var attributedString = NSMutableAttributedString.init(string: "Privacy")
attributedString.addAttribute(.link, value: "https://www.google.com/url?q=https://www.iubenda.com/privacy-policy/58446596&sa=D&source=hangouts&ust=1528787597335000&usg=AFQjCNEPkofPxSm7TDRMvxjOjCz5cio27w", range: NSRange(location: 0, length: 7))
label.isUserInteractionEnabled = true
label.text = firstTermsMessage
label.font = UIFont.systemFont(ofSize: 13, weight: .regular)
label.textAlignment = .left
label.numberOfLines = 0
label.translatesAutoresizingMaskIntoConstraints = false
label.heightAnchor.constraint(equalToConstant: 36).isActive = true
return label
}()
【问题讨论】:
-
你在哪里设置属性字符串?
-
@karthikeyan " var attributesString = NSMutableAttributedString.init(string: "Privacy") attributesString.addAttribute(.link, value: "google.com/url?q=https://www.iubenda.com/privacy-policy/…", range: NSRange(location: 0, length: 7 ))"
-
不要使用
UILabel,使用UITextView。 Cf here at 2:00 developer.apple.com/videos/play/wwdc2018/221 “选择正确的控制”部分。 -
@Larme 好的,我替换了,如何将链接添加到单词? “attributedString”方法似乎一直没有看到我..
-
Textview.attributedText = 属性字符串,而不是 .text
标签: ios iphone swift xcode uilabel