Half text can be click Use "SwiftyAttributes"
if you want to know how to make some of the labels click, this is how I make it. use cocoapod SwiftyAttributes
pod 'SwiftyAttributes'
example:
"Hello World".withUnderlineColor(.red).withUnderlineStyle(.styleDouble)
https://github.com/eddiekaiger/SwiftyAttributes
Fullcode
import UIKit
import SwiftyAttributes
class SwiftAttributeVC: UIViewController {
@IBOutlet weak var labelAttribute: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let agreement = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. ".withFont(self.labelAttribute.font) + "Terms ".withTextColor(.blue).withFont(self.labelAttribute.font) + "& ".withFont(self.labelAttribute.font) + " Conditions".withTextColor(.blue).withFont(self.labelAttribute.font)
self.labelAttribute.attributedText = agreement
let tapAction = UITapGestureRecognizer(target: self, action: #selector(self.tapLabel))
// let tapAction2 = UITapGestureRecognizer(target: self, action: #selector(self.tapLabel2))
self.labelAttribute.isUserInteractionEnabled = true
self.labelAttribute.addGestureRecognizer(tapAction)
}
@objc func tapLabel(gesture: UITapGestureRecognizer) {
print("test 1")
let text = (labelAttribute.text)!
let termsRange = (text as NSString).range(of: "Terms & Conditions")
}
}
No comments: