Skip to content

Instantly share code, notes, and snippets.

@gali8
Created September 9, 2019 15:25
Show Gist options
  • Save gali8/b7957497fe1dcc962335ef77f138748e to your computer and use it in GitHub Desktop.
Save gali8/b7957497fe1dcc962335ef77f138748e to your computer and use it in GitHub Desktop.
class LabelBody: LabelTappable {
var body: String? {
get {
return self.attributedText?.string
}
set {
self.text = nil
guard let text = newValue, !text.isEmpty else {
self.attributedText = nil
return
}
self.attributedText = text.html(font: self.font)
self.didTap = { [weak self] label, characterIndex in
guard let _ = self else {
return
}
if let url = label.attributedText?.attribute(.link, at: characterIndex, effectiveRange: nil) as? URL, UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment