Created
September 9, 2019 15:25
-
-
Save gali8/b7957497fe1dcc962335ef77f138748e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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