Last active
June 4, 2018 11:42
-
-
Save Athosone/405be93d2b4b73c74224 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
extension UITextField { | |
func designTextField(placeholder: String,content: String?){ | |
let paddingView = UIView(frame: CGRectMake(0, 0, 15, self.frame.height)) | |
self.enabled = true | |
self.leftView = paddingView | |
self.leftViewMode = UITextFieldViewMode.Always | |
self.layer.cornerRadius = self.bounds.height * 0.5 | |
self.backgroundColor = EA_DesignHelper.textFieldBackgroundColor | |
self.layer.borderColor = EA_DesignHelper.textFieldBorderColor.CGColor | |
self.layer.borderWidth = EA_DesignHelper.textFieldBorderWidth | |
self.attributedPlaceholder = NSAttributedString(string:NSLocalizedString(placeholder,comment:""), | |
attributes:[NSForegroundColorAttributeName: EA_DesignHelper.textFieldPlaceHolderColor ]) | |
self.textColor = EA_DesignHelper.textFieldTextColor | |
} | |
func designTextFieldNoneEditable(placeholder: String,content: String?){ | |
self.designTextField(placeholder, content: content) | |
self.layer.borderWidth = 0.0 | |
self.enabled = false | |
} | |
//MARK Forms validation | |
func validateHorseName() -> (Bool, String?) | |
{ | |
if self.text?.isEmpty ?? true | |
{ | |
return (false, NSLocalizedString("Horse's name must not be empty", comment: "")) | |
} | |
return (true, nil) | |
} | |
func validateHorseAge() -> (Bool, String?) | |
{ | |
if self.text?.isEmpty ?? true | |
{ | |
return (false, NSLocalizedString("Horse's age must not be empty", comment: "")) | |
} | |
return (true, nil) | |
} | |
static func textFieldsForView(view:UIView) -> [UITextField] | |
{ | |
var textFields:[UITextField] = [UITextField]() | |
view.subviews.forEach { (subView:UIView) -> () in | |
if let tf:UITextField = subView as? UITextField | |
{ | |
textFields.append(tf) | |
} | |
else if subView.respondsToSelector("subviews") | |
{ | |
textFields.appendContentsOf(UITextField.textFieldsForView(subView)) | |
} | |
} | |
return textFields | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment