swift 使标签在 UIviewcontroller 中可点击
swift make label clickable in UIviewcontroller
我希望标签可点击以在 safari 中打开 url,
单击
时 phone 中的数字和电子邮件中的电子邮件地址
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
}
}
})
我添加了这个功能,但它不起作用:
if let Website1 = dict["Website1"] as? String {
self.Website1L.text = Website1
let weblurl = NSURL(string: "open page:\(Website1)")
UIApplication.sharedApplication().openURL(weblurl!)
}
尝试使用 UITextView。如果您不希望用户能够编辑 UITextView 内的文本,您可以在 UITextView 的属性检查器中取消选中 "Editable"。如果您希望 UITextView 能够检测文本字符串,例如 links、phone 数字、事件和地址,您可以在 UITextView 的属性检查器中检查适用的。
如果您知道只会显示一个 link,只需添加一个带有您想要的文本的按钮,然后将其发送到 Safari。
我希望标签可点击以在 safari 中打开 url, 单击
时 phone 中的数字和电子邮件中的电子邮件地址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
}
}
})
我添加了这个功能,但它不起作用:
if let Website1 = dict["Website1"] as? String {
self.Website1L.text = Website1
let weblurl = NSURL(string: "open page:\(Website1)")
UIApplication.sharedApplication().openURL(weblurl!)
}
尝试使用 UITextView。如果您不希望用户能够编辑 UITextView 内的文本,您可以在 UITextView 的属性检查器中取消选中 "Editable"。如果您希望 UITextView 能够检测文本字符串,例如 links、phone 数字、事件和地址,您可以在 UITextView 的属性检查器中检查适用的。
如果您知道只会显示一个 link,只需添加一个带有您想要的文本的按钮,然后将其发送到 Safari。