LabelTapGesture An extension for setup UILabel with custom hyperlink styling, and interaction when tap on link.
๐ฒ Installation
LabelTapGesture
is available on CocoaPods:
pod 'LabelTapGesture'
๐ How
Code Implementation
import LabelTapGesture
Example Terms and Conditions Label.
@IBOutlet var termsConditionLabel: UILabel!
// Example Terms and Conditions text.
let text:String = "By signing up you confirm your agreement with our terms and conditions. Weโll never share your information"
let textAttributes:[NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 16)]
let rangeText:String = "terms and conditions"
let rangeTextAttributes:[NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 16),
.foregroundColor: UIColor.blue,
.underlineStyle: NSUnderlineStyle.single]
self.termsConditionLabel.addTapGesture(text: text, textAttributes: textAttributes,
tapOnText: rangeText, tapOnTextAttributes: rangeTextAttributes) {
// Handles when tapping the rangeText on the label.
}
๐ Requirements
- iOS 10.0+
- Xcode 11+
- Swift 5.1+