0

i want label clickable to open url in safari , number in phone and email address in email when click

override func viewDidLoad() {
  super.viewDidLoad()

  // DetailsSV.contentSize.height=1120

  print("idis \(self.strUserid)")

  let ref = Firebase(url: "https://businesswallet.firebaseio.com/Users")

  ref.childByAppendingPath(self.strUserid as String).observeEventType(.Value, withBlock: { snapshot in
    if let dict = snapshot.value as? NSMutableDictionary{
      print("dict is \(dict)")
      if let Email = dict["Email"] as? String {
        self.EmailL.text = Email
      }
      if let name = dict["BusinessName"] as? String {
        self.BusinessNameL.text = name
        self.navigationItem.title = name
      }
      if let ShortDescription = dict["ShortDescription"] as? String {
        self.ShortDescriptionL.text = ShortDescription
      }
      if let City = dict["City"] as? String {
        self.CityL.text = City
      }
      if let ContactMe = dict["ContactMe"] as? String {
        self.ContactMeL.text = ContactMe
      }
      if let PhoneNumber = dict["PhoneNumber"] as? String {
        self.PhoneNumberL.text = PhoneNumber
      }
      if let Website1 = dict["Website1"] as? String {
        self.Website1L.text = Website1
      }
      if let Website2 = dict["Website2"] as? String {
        self.Website2L.text = Website2
      }
      if let Category = dict["Category"] as? String {
        self.CategoryL.text = Category
      }
      if let Details = dict["Details"] as? String {
        self.DetailsTV.text = Details
      }
    }
  })

i was add this function but it doesn't work :

if let Website1 = dict["Website1"] as? String {
  self.Website1L.text = Website1
  let weblurl = NSURL(string: "open page:\(Website1)")
  UIApplication.sharedApplication().openURL(weblurl!)
}
Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
bashayr.m
  • 5
  • 2
  • UITextView has built-in support for detecting and handling links, numbers, addresses, etc. If you turn off the scrolling it's basically a fancy label. – Matthew Seaman May 02 '16 at 15:54
  • In the interface builder you can make the label highlight addresses, links, etc. You can even make it intractable. If the text is larger, you can use a textView to do all the same thing. These objects are very powerful. – modesitt May 02 '16 at 16:33
  • Why don't you just use a `UIButton`? You can stylize it to look any way you want, and it comes with a `TouchUpInside` handler. – ZGski May 02 '16 at 20:38

1 Answers1

0

Try using a UITextView. If you don't want the user to be able to edit the text inside of the UITextView, you can un-check "Editable" in the UITextView's Attributes Inspector. If you want the UITextView to be able to detect strings of text like links, phone numbers, events, and addresses, you can check the applicable ones in UITextView's Attributes Inspector.

If you know there is only going to be one link that you want to show, just add a button with the text that you want and have it send the user over to Safari.

Dan Levy
  • 3,931
  • 4
  • 28
  • 48