2

I am trying to set Hyperlink in the text. Text appears but i cannot find the link on the text. Can anyone help here. I want to set the link on My Health Action Plan on getStartedDict. but only whole text appears without any links.

let link1 = ["My Health Action Plan"]
var getStartedDict =
   ["":"Now that you have a glimpse of where you currently are in managing your health, it is time for you to update your Health Action Plan. Use the information in the Health Profile along with the online resources in this portal to help set realistic health goals and to help you work toward better health."]
var linkArray = [[String]]()

override func viewDidLoad(){
    super.viewDidLoad()
    linkArray.removeAll()
    linkArray.append(link1)
    CommonUtility.sharedInstance.addBackButton(self)
    loadData()
 }

//here i tried to set the link

  if let getStartedText = self.getStartedDict[self.model.label1]?.htmlStringToAttributedString()
        {
            let aText = getStartedText
            let myRange = NSRange(location: 0, length: aText.length)
            aText.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(kFontSize), range: myRange)
            print(aText)
            cell.detail.setLinksForSubstrings(linkArray, withLinkHandler: handler)

        }

Updated: Refer to comment for answer

Niroj
  • 1,114
  • 6
  • 29

1 Answers1

0

finally after long hours of Headache i have done this:

var getStartedDict =
   ["Value":"Now that you have a glimpse of where you currently are in managing your health, it is time for you to update your Health Action Plan. Use the information in the Health Profile along with the online resources in this portal to help set realistic health goals and to help you work toward better health."]

 override func viewDidLoad(){
        super.viewDidLoad()
        CommonUtility.sharedInstance.addBackButton(self)
        loadData()
     }

This is how we can set the link

if let getText = self.getStartedDict["Value"]?.htmlStringToAttributedString(){
        let aText = getText
        let myRange = NSRange(location: 0, length: aText.length)
        aText.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(kFontSize), range: myRange)
        cell.detail.attributedText = aText
        cell.detail.setLinksForSubstrings(["Health Action Plan"], withLinkHandler: handler)
    }
    else{
        print("No text found")
    }

Fell free to comment in case, if there is a better way for this.

Niroj
  • 1,114
  • 6
  • 29