Skip to content

Commit 84e47a4

Browse files
author
Ahmet Sina Ustem
committed
Font Awesome added for TextFields
1 parent 9a56c7a commit 84e47a4

47 files changed

Lines changed: 8145 additions & 1124 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ALFormInput.podspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ Pod::Spec.new do |s|
2525
s.dependency 'SwiftValidatorNew', '~> 4.2.0'
2626
s.dependency 'ActionSheetPicker-3.0'
2727
s.dependency 'AlExtensions'
28+
s.dependency 'FontAwesome.swift'
29+
2830
end

ALFormInput/Classes/ALDatePicker.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public class ALDatePicker: ALValidatableTextField {
2828
public override init(rules: [Rule], config: ALTextFieldConfig) {
2929
super.init(rules: rules, config: config)
3030
delegate = self
31+
setDropDownIcon()
3132
}
3233

3334
public required init?(coder: NSCoder) {
3435
super.init(coder: coder)
3536
delegate = self
37+
setDropDownIcon()
3638
}
3739

3840
public func setupPicker(pickerMode: UIDatePickerMode? = nil,

ALFormInput/Classes/ALStringPicker.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public class ALObjectPicker: ALValidatableTextField {
2828
public override init(rules: [Rule], config: ALTextFieldConfig) {
2929
super.init(rules: rules, config: config)
3030
delegate = self
31+
setDropDownIcon()
3132
}
3233

3334
public required init?(coder: NSCoder) {
3435
super.init(coder: coder)
3536
delegate = self
37+
setDropDownIcon()
3638
}
3739

3840
public func setupPicker(objects: [ALPickable]? = nil, selectedObject: ALPickable? = nil) {

ALFormInput/Classes/ALValidatableConfig.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import UIKit
9+
import SkyFloatingLabelTextField
910

1011
public class ALTextFieldConfig {
1112
static let shared = ALTextFieldConfig()
@@ -57,6 +58,21 @@ public class ALTextFieldConfig {
5758

5859
public var validateEventType: UIControl.Event = .editingDidEnd
5960

61+
public var iconType: IconType = .image
62+
63+
public var iconColor: UIColor {
64+
titleColor
65+
}
66+
67+
public var selectedIconColor: UIColor {
68+
selectedTitleColor
69+
}
70+
71+
public var iconWidth: CGFloat {
72+
isIconVisible ? 20 : -4
73+
}
74+
75+
public var isIconVisible: Bool = false
6076

6177
public init () {}
6278
}

ALFormInput/Classes/ALValidatableTextField.swift

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import SkyFloatingLabelTextField
1111
import PhoneNumberKit
1212
import SwiftValidatorNew
1313
import 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

Comments
 (0)