I have a UIlabel and it's text like following
label.text = "#fun #fun #google #youtube"
I want to make the UILabel clickable and open it's url.
I also make the dictionary to set it's keys&values.
var dic:[String:String] = ["https://www.yahoo.com.tw/" :"fun",
"https://www.facebook.com.tw/":"fun",
"https://www.google.com.tw/" :"Google",
"https://www.youtube.com/" :"Youtube"
]
//How about change it's type to array?
var arr:[[String:String]] = [["https://www.yahoo.com.tw/" :"fun"],
["https://www.facebook.com.tw/":"fun"],
["https://www.google.com.tw/" :"Google"],
["https://www.youtube.com/" :"Youtube"]
]
How to seprate "fun" to load different url When I click "#fun"?
I use third-library ActiveLabel.swift to achieve UILabel clickable.
label.handleHashtagTap({ (string) in
//do something.
let keys = self.dic.allKeys(forValue: "#\(string) ")
print("--> keys: \(keys)")
})
extension Dictionary where Value: Equatable {
func allKeys(forValue val: Value) -> [Key] {
return self.filter { $1 == val }.map { $0.0 }
}
}