AbstractPlaceholderService
public protocol AbstractPlaceholderService
Protocol for abstract service, which contains logic for drawing placeholder.
This protocol have main methods to draw placeholder as you want. Some methods is optional.
If you want to use you own custom placeholder service - you may implement service with this protocol.
-
Method setups input field (textField or textView) with superview on your placeholder.
In this method you can add you placeholder container (eg UILabel or CATextLayer) on superview or handle weak link on you field/superview.
Important
Method will call on- field initialization
- configuration refresh
- or when you add service to your field
Declaration
Swift
func provide(superview: UIView, field: InputField?)
Parameters
superview
View where you have to place you placeholder
field
TextField/TextView where user will be enter some text
-
Method allows you to setup some string in your placeholder.
In this method you have to setup placeholder string in placeholder container.
Important
The only place where method will be called from frameworks field - isfunc configure(placeholder: String?)
method. If you have more than one placeholder service - you have to provide string yourself.Declaration
Swift
func setup(placeholder: String?)
Parameters
placeholder
String for placeholder
-
Method allows you to configure placeholder initial state.
Important
This method will be called on- field initialization
- and when you add service to your field
Declaration
Swift
func configurePlaceholder(fieldState: FieldState, containerState: FieldContainerState)
Parameters
fieldState
State of field
containerState
State of field container (have more states compared with fieldState)
-
Method allows you to configure placeholder for appropriate state.
This is main method where you have to place logic for placeholder state refreshing.
Important
This method will be called on- field initialization
- and when UI have some significant changes (eg user enter text, error occured, etc)
Declaration
Swift
func updateContent(fieldState: FieldState, containerState: FieldContainerState, animated: Bool)
Parameters
fieldState
State of field
containerState
State of field container (have more states compared with fieldState)
-
update(useIncreasedRightPadding:
Default implementationfieldState: animated: ) This method will be called when you add/remove additional action button.
In this method you have to place logic for refreshing placeholder frame, so that it does not overlap the button.
Important
This is optional method. You can leave it empty if you doesn’t use action button or if you placeholder never overlap it.Default Implementation
Declaration
Swift
func update(useIncreasedRightPadding: Bool, fieldState: FieldState, animated: Bool)
Parameters
useIncreasedRightPadding
Flag indicating whether you should use increased right padding for your placeholder (if action button is visible) or not
fieldState
State of field
-
updateAfterTextChanged(fieldState:
Default implementation) This method will be called when user enter some text in field, but state of field doesn’t changed.
Important
This is optional method. You can leave it empty if you don’t need to such logic.Default Implementation
Declaration
Swift
func updateAfterTextChanged(fieldState: FieldState)
Parameters
fieldState
State of field