@@ -11,8 +11,9 @@ import SkyFloatingLabelTextField
1111import PhoneNumberKit
1212import SwiftValidatorNew
1313import ActionSheetPicker_3_0
14+ import FontAwesome_swift
1415
15- public class ALValidatableTextField : SkyFloatingLabelTextField {
16+ public class ALValidatableTextField : SkyFloatingLabelTextFieldWithIcon {
1617
1718 private let validator = Validator ( )
1819 private var config = ALTextFieldConfig ( )
@@ -21,6 +22,55 @@ public class ALValidatableTextField: SkyFloatingLabelTextField {
2122 private lazy var phoneNumberKit = PhoneNumberKit ( )
2223 private lazy var phoneFormatter = PartialFormatter ( )
2324
25+ /// When you search your icon on fontawesome.com click on icon that you want.
26+ /// In its URL you will see its style. For example for camera icon it will be like this: ../icons/camera?style=solid
27+ /// For example for camera icon it will be like this: ../icons/camera?style=solid
28+ public var fontAwesomeStyle : FontAwesomeStyle = . regular {
29+ didSet {
30+ updateIcon ( )
31+ }
32+ }
33+
34+
35+ /// Check your free FontAwesome icon in https://fontawesome.com/icons?d=gallery
36+ public var fontAwesomeImage : FontAwesome ? {
37+ didSet {
38+ guard let fontAwesomeImage = fontAwesomeImage else { return }
39+ DispatchQueue . main. async {
40+ self . iconImage = UIImage . fontAwesomeIcon ( name: fontAwesomeImage,
41+ style: self . fontAwesomeStyle,
42+ textColor: self . errorMessage != nil ? self . errorColor : self . titleColor,
43+ size: CGSize ( width: 40 , height: 40 ) )
44+ }
45+
46+ }
47+ }
48+
49+
50+ /// Update icon when states changed
51+ private func updateIcon( ) {
52+ let fontImage = fontAwesomeImage
53+ fontAwesomeImage = fontImage
54+ }
55+
56+ public override var errorMessage : String ? {
57+ didSet {
58+ updateIcon ( )
59+ }
60+ }
61+
62+ public override var iconImage : UIImage ? {
63+ willSet {
64+ DispatchQueue . main. async {
65+ self . config. isIconVisible = self . iconImage != nil
66+ self . iconColor = self . config. iconColor
67+ self . selectedIconColor = self . config. selectedIconColor
68+ self . iconWidth = self . config. iconWidth
69+ self . iconType = self . config. iconType
70+ self . layoutIfNeeded ( )
71+ }
72+ }
73+ }
2474
2575 // MARK: - Properties
2676 private var padding : UIEdgeInsets ? {
@@ -58,12 +108,12 @@ public class ALValidatableTextField: SkyFloatingLabelTextField {
58108 }
59109
60110
61- public func setConfig( _ type: ALValidatableTextFieldType = . optional,
62- _ config: ALTextFieldConfig = ALTextFieldConfig ( ) ,
63- rules: [ Rule ] = [ ] ,
64- validateWhileTyping: Bool = false
65- ) {
111+ public func setConfig( _ config: ALTextFieldConfig = ALTextFieldConfig ( ) ) {
66112 self . config = config
113+ }
114+
115+ public func setTypesAndRules( _ type: ALValidatableTextFieldType = . optional,
116+ rules: [ Rule ] = [ ] ) {
67117 self . type = type
68118 let tmpRules = rules. isEmpty ? type. rules : rules
69119 keyboardType = type. keyboardType
@@ -96,6 +146,11 @@ public class ALValidatableTextField: SkyFloatingLabelTextField {
96146 selectedLineColor = config. selectedLineColor
97147 titleColor = config. titleColor
98148
149+ iconColor = config. iconColor
150+ selectedIconColor = config. selectedIconColor
151+ iconWidth = config. iconWidth
152+ iconType = config. iconType
153+
99154 errorColor = config. errorColor
100155 textErrorColor = config. textErrorColor
101156 lineErrorColor = config. lineErrorColor
@@ -202,6 +257,10 @@ public class ALValidatableTextField: SkyFloatingLabelTextField {
202257 return nil
203258 }
204259
260+ internal func setDropDownIcon( ) {
261+ fontAwesomeImage = . angleDown
262+ fontAwesomeStyle = . solid
263+ }
205264
206265 func validationSuccessful( ) {
207266 // submit the form
0 commit comments