Skip to content

gbksoft/gbktextfield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GBKSoft UITextField

Preview

Material inspired implementation for UITextField based on design trends used in GBKSoft

Requirements

  • iOS 10.0+

Installation

CocoaPods

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

Usage

Xib

  • Add new UITextField in Interface Builder
  • Specify GBKSoftTextField as Custom Class in Identity Inspector for that field
  • Fill any needed properties in Attributes Inspector

Code

    import GBKSoftTextField
    
    ...
    let firstNameTextField = GBKSoftTextField()
    firstNameTextField.placeholder = "First Name"
	// TODO: specify any other available properties
    view.addSubview(firstNameTextField)

Properties

Properties

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 = .green

Additional Info

isInline

Property isInline define appearance and behaviour of the field

isInline == false (default)

Default example

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

isInline == true

Inline example

In inline mode title position is fixed for any state. Title and field stacked horizontally

Delegate

In case you need to handle right button tap you should assign GBKSoftTextFieldDelegate as field delegate instead default UITextFieldDelegate

Xib (recommended)

Inline example Inline example

Code

    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

ToDo

  • add multiline support by inheritance from UITextView

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published