This file contains 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
// let MAX_LENGTH_PHONENUMBER = 15 | |
// let ACCEPTABLE_NUMBERS = "0123456789" | |
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | |
let newLength: Int = textField.text!.characters.count + string.characters.count - range.length | |
let numberOnly = NSCharacterSet.init(charactersIn: ACCEPTABLE_NUMBERS).inverted | |
let strValid = string.rangeOfCharacter(from: numberOnly) == nil | |
return (strValid && (newLength <= MAX_LENGTH_PHONENUMBER)) |
This file contains 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
func setStatusBarBackgroundColor(color: UIColor) { | |
guard let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView else { | |
return | |
} | |
statusBar.backgroundColor = color | |
} |