gpt4 book ai didi

ios - UIAlertcontroller 中的可点击 url

转载 作者:行者123 更新时间:2023-12-05 08:11:33 26 4
gpt4 key购买 nike

是否可以创建一个警报,其中包含一条消息,其中包含带有可点击 URL 的文本,并在 Safari 中进一步重定向?示例:https://prntscr.com/lujcx5

enter image description here

最佳答案

你可能想试试这个,

    let alert = UIAlertController(title: "Default Title", message: nil, preferredStyle: .alert)
let textView = UITextView()
textView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

let controller = UIViewController()

textView.frame = controller.view.frame
controller.view.addSubview(textView)
textView.backgroundColor = .clear

alert.setValue(controller, forKey: "contentViewController")

let height: NSLayoutConstraint = NSLayoutConstraint(item: alert.view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 150)
alert.view.addConstraint(height)

let attributedString = NSMutableAttributedString(string: "http://movies.com")
let url = URL(string: "http://movies.com")

attributedString.setAttributes([.link: url ?? ""], range: NSMakeRange(0, attributedString.length))


textView.attributedText = attributedString
textView.isUserInteractionEnabled = true
textView.isEditable = false

// Set how links should appear: blue and underlined
textView.linkTextAttributes = [
.foregroundColor: UIColor.blue,
.underlineStyle: NSUnderlineStyle.single.rawValue
]

let okAction = UIAlertAction(title: "OK", style: .default) {
UIAlertAction in
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) {
UIAlertAction in
}

alert.addAction(okAction)
alert.addAction(cancelAction)

present(alert, animated: true, completion: nil)

输出应该是这样的, image

关于ios - UIAlertcontroller 中的可点击 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53765445/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com