Material inspired implementation for UITextField based on design trends used in GBKSoft
- iOS 10.0+
To integrate GBKSoftTextField into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'GBKSoftTextField', :git => 'git@gitlab.gbksoft.net:gbksoft-mobile-department/ios/gbksofttextfield.git'Then, run the following command:
$ pod install- Add new
UITextFieldin Interface Builder - Specify
GBKSoftTextFieldas Custom Class in Identity Inspector for that field - Fill any needed properties in Attributes Inspector
import GBKSoftTextField
...
let firstNameTextField = GBKSoftTextField()
firstNameTextField.placeholder = "First Name"
// TODO: specify any other available properties
view.addSubview(firstNameTextField)| Property | Type | Default value | Description | @IBInspectable |
|---|---|---|---|---|
| textPadding | CGSize | (width: 0, height: 10) | Horizontal and vertical edge insets for input field | ✔️ |
| errorPadding | CGSize | (width: 0, height: 10) | Horizontal and vertical edge insets for input field | ✔️ |
| underlineHeight | CGFloat | 1 | Height of underline for unfocused state | ✔️ |
| underlineEditingHeight | CGFloat | 2 | Height of underline for focused state | ✔️ |
| underlineErrorHeight | CGFloat | 2 | Height of underline for field when error displayed | ✔️ |
| placeholderColor | UIColor | UIColor.gray | Placeholder color | ✔️ |
| titleColor | UIColor | UIColor.gray | Title color | ✔️ |
| errorColor | UIColor | UIColor.red | Color for error message and underline when error displayed | ✔️ |
| underlineColor | UIColor | UIColor.gray | Underline color for unfocused state | ✔️ |
| underlineEditingColor | UIColor | UIColor.blue | Underline color for focused state | ✔️ |
| titleAnimated | Bool | false | Define if title position animated when field change focus state | ✔️ |
| errorAnimated | Bool | false | Define if error message appear animated | ✔️ |
| title | String | nil | Title of the field. If no placeholder provided it will be used as placeholder | ✔️ |
| error | String | nil | Error message. Error message shown and underline changed color only if error != nil |
✔️ |
| isInline | Bool | false | Field display mode. More | ✔️ |
| inlineFieldOffset | CGFloat | 100 | Title width for inline mode | ✔️ |
| buttonVisible | Bool | false | Right button visibility | ✔️ |
| buttonImage | UIImage | nil | Right button icon | ✔️ |
| buttonTintColor | UIColor | UIColor.gray | Right button icon tint color. Provided image always render as template |
✔️ |
| clearErrorOnFocus | Bool | true | Define if error should disappear on field become first responder | ✔️ |
| titleFont | UIFont | nil | Title font. By default will be used field font with UIFont.labelFontSize |
❌ |
| placeholderFont | UIFont | nil | Placeholder font. By default will be used field font with UIFont.systemFontSize |
❌ |
| errorFont | UIFont | nil | Error message font. By default will be used field font with UIFont.labelFontSize |
❌ |
All properties can be set globally for GBKSoftTextField.appearence()
GBKSoftTextField.appearence().titleFont = UIFont.systemFont(ofSize: 20)
GBKSoftTextField.appearence().underlineColor = .greenProperty isInline define appearance and behaviour of the field
By default for empty field only placeholder and underline are displayed. On focus and when text is not empty placeholder will be hidden and title appear. Title and field stacked vertically
In inline mode title position is fixed for any state. Title and field stacked horizontally
In case you need to handle right button tap you should assign GBKSoftTextFieldDelegate as field delegate instead default UITextFieldDelegate
import GBKSoftTextField
...
firstNameTextField.textFieldDelegate = self
...
extension ViewController: GBKSoftTextFieldDelegate {
...
}In addition to default functions of UITextFieldDelegate this protocol provide next one
func textFieldDidTapButton(_ textField: UITextField)that will be called when user tapped right button
- add multiline support by inheritance from UITextView





