Skip to content

Commit

Permalink
Updating to use the UITextFieldDelegate delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
gergelyorosz committed Apr 4, 2016
1 parent d00dd1c commit afe28a2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ self.view.addSubview(textField2)

The textfield supports displaying an error state - this can be useful for example when validating fields on the fly. When the `errorMessage` property is set on the control, then the control is highlighted with the color set in the `errorColor` property.

To get notified of different events happening on the textfield - such as the text changing, editing starting or ending - just set the `delegate` property to a class implementing the `SkyFloatingLabelTextFieldDelegate` protocol. This delegate is very similar to the [UITextFieldDelegate protocol](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextFieldDelegate_Protocol/):
To get notified of different events happening on the textfield - such as the text changing, editing starting or ending - just set the `delegate` property to a class implementing the standard [UITextFieldDelegate](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextFieldDelegate_Protocol/) protocol:

![](/SkyFloatingLabelTextField/images/example-4.gif)

```swift
class MyViewController: UIViewController, SkyFloatingLabelTextFieldDelegate {
class MyViewController: UIViewController, UITextFieldDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let textField1 = SkyFloatingLabelTextField(frame: CGRectMake(10, 10, 120, 45))
Expand All @@ -116,8 +116,8 @@ class MyViewController: UIViewController, SkyFloatingLabelTextFieldDelegate {
self.view.addSubview(textField1)
}

/// Implementing a method on the SkyFloatingLabelTextFieldDelegate protocol. This will notify us when something has changed on the textfield
func textFieldChanged(textField: SkyFloatingLabelTextField) {
/// Implementing a method on the UITextFieldDelegate protocol. This will notify us when something has changed on the textfield
func textFieldChanged(textField: UITextField) {
if let text = textField.text {
// Note: every time when the text of the textfield changes, the error message is reset (hence we don't need to reset it)
if(text.characters.count < 3 || !text.containsString("@")) {
Expand Down

0 comments on commit afe28a2

Please sign in to comment.