HyperLabel is a UILabel replacement which suports adding links for arbitraray part of the text
HyperLabel supports setting custom accessibilityIdentifier
for added links
All added links will have proper description and will be accessible with VoiceOver
If you already have a subclass of UILabel, you can add HyperLabel functionallity to it. Just by conform it to HyperLabelProtocol
and call initializeHyperLabel
let label = HLHyperLabel()
// Set additional attributes which will be applied for added links
label.additionalLinkAttributes = [
NSAttributedString.Key.foregroundColor: UIColor.red,
NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue
]
// Set text
label.text = "Hello world!"
// Get range of the link
let linkRange = (text as NSString).range(of: "world")
// Add handler for range
label.addLink(withRange: linkRange) {
// On link press
}
Add HyperLabel to your Cartfile:
github "badoo/HyperLabel"
- Add as a submodule or download
- Drag
HyperLabel.xcodeproj
inside of your project - Add
HyperLabel.framework
to Target Dependencies - Add
HyperLabel.framework
to Embedded Binaries
Source code is distributed under MIT license