I have cerated a custom UITextfield class according to my application UI. But I want some of the delegate methods to be included into the class so I do not need to write them in all the classes.
open class SAIconTextField: SkyFloatingLabelTextFieldWithIcon {
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
configure()
}
/// Override init method
override init(frame: CGRect) {
super.init(frame: frame)
configure()
}
/// Override layoutSubviews method
override open func layoutSubviews() {
super.layoutSubviews()
}
/// This method is used to set general UI
func configure() {
self.tintColor = UIColor.appBlue
self.selectedTitleColor = .appBlue
self.selectedLineColor = .appBlue
self.selectedLineHeight = 0.5
self.iconColor = .lightGray
self.iconImageView.tintColor = .lightGray
self.selectedIconColor = .appBlue
self.iconMarginBottom = 7.0
// self.iconMarginLeft = 2.0
self.errorColor = .errorColor
}
}
I have extended my class to perform a delegate method so that all the textfields prevent entering emojis in my app, but the method is not called.
// MARK: - UITextFieldDelegate
extension SAIconTextField: UITextFieldDelegate {
/// Delegate method
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if textField.textInputMode?.primaryLanguage == "emoji" || !((textField.textInputMode?.primaryLanguage) != nil) {
return false
}
return true
}
}
Any other way to do the similar things?