10

My app screenshot

I want alert dialog box like this image. which contains a clickable link like blue highlighted text. when user click on that text, it will open a link in browser. For this i am using third party library SimpleAlert

here is my code...

func popUpMsg(){

    let msg = "\n Hi Rahul! Welcome back to the early access queue for the app, Once you've been accepted into the beta, we'll notify you using the contact info you have on file with Facebook. \n\n But just a second, if you haven't already done so, you can increase your odds of jumping ahead in the queue by telling us a little about yourself. Please complete our 4-question survey to give it a shot. \n" as NSString
    let range = msg.rangeOfString("complete our 4-question survey")

    let alert = SimpleAlert.Controller(title: "Early Access to Application", message: msg as String, style: .Alert)
    alert.configContentView = { view in
        if let view = view as? SimpleAlert.ContentView {
            view.titleLabel.textColor = UIColor.blackColor()
            view.titleLabel.font = UIFont.boldSystemFontOfSize(32)
            print(view.titleLabel.font)
            view.messageLabel.textColor = UIColor.grayColor()

            let attributedString = NSMutableAttributedString(string: msg as String)
            attributedString.addAttribute(NSLinkAttributeName, value: NSURL(string: "http://www.google.com")!, range: range)
            attributedString.addAttribute(NSUnderlineStyleAttributeName, value: NSNumber(int: 1), range: range)
            attributedString.addAttribute(NSUnderlineColorAttributeName, value: UIColor.whiteColor(), range: range)

            view.messageLabel.attributedText = attributedString
            view.messageLabel.font = UIFont(name: "arial", size: 27)
            print(view.messageLabel.font)

            view.textBackgroundView.layer.cornerRadius = 3.0
            view.textBackgroundView.clipsToBounds = true
        }
    }
    alert.addAction(SimpleAlert.Action(title: "OK", style: .OK))
    presentViewController(alert, animated: true, completion: nil)
}
Rahul singh
  • 251
  • 3
  • 20
  • So what's your problem ? – Chajmz May 04 '16 at 11:12
  • 2
    Why don't you redirect the actual page while click on OK button ? It is better for programming rather than link in alert view. – Jigar Tarsariya May 04 '16 at 11:52
  • you are correct but this is not my client requirement... – Rahul singh May 04 '16 at 12:04
  • 1
    Then explain to your client that Apple has guidelines for User Experience and tell him that is always best to follow those. (even if those guidelines say nothing about a link in text in an alert) Educating the client is part of a developers job. – R Menke May 04 '16 at 12:20
  • 4
    Guidelines or not, I'd also like to be able to make hyperlinks within the message text of a UIAlertController, with the `OK` button reserved for making the controller go away. I can already create the links, but they're not (yet) clickable. – Alnitak Aug 08 '16 at 16:02
  • @Rahulsingh Did you find a solution yet? – A_G May 26 '17 at 07:57
  • @AsthaGupta ..... Yes, i found..instead of UILabel use UITextView. Add NSLinkAttributeName attribute and then use UITextView delegate method : func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool { ... } – Rahul singh May 26 '17 at 12:11
  • https://stackoverflow.com/questions/21629784/how-to-make-a-clickable-link-in-an-nsattributedstring-for-a Refer this link – BHAVIK Jul 10 '17 at 06:43

0 Answers0