How to add hyperlink in iPhone app?

后端 未结 5 2202
无人共我
无人共我 2020-12-09 22:13

In my iPhone app, I require to show the hyperlink to a website

How can I add hyperlink for a website in iPhone programming?.

Actually i want to pass the lin

5条回答
  •  天涯浪人
    2020-12-09 23:04

    extension NSAttributedString{

    add a new swift file for adding link in ios

      static func makeHyperlink(for path: String, in string: String, as substring: String) -> NSAttributedString {
        let nsString = NSString(string: string)
        let substringRange = nsString.range(of: substring)
        let attributedString = NSMutableAttributedString(string: string)
        attributedString.addAttribute(.link, value: path, range: substringRange)
        return attributedString
    }
    

    }

    And then use this makehyperlink function in your text view function.

    let attributedString = NSAttributedString.makeHyperlink(for: link, in: paragraph, as: "text to use for link")

提交回复
热议问题