Created
July 19, 2017 12:40
-
-
Save rcdilorenzo/bdd344aeb63980cfee2f2112a7fca851 to your computer and use it in GitHub Desktop.
Various iOS extensions for creating reusable views in code
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
import UIKit | |
extension UILabel { | |
static func createTitle(text: String, light: Bool, oversized: Bool) -> UILabel { | |
let label = UILabel() | |
label.translatesAutoresizingMaskIntoConstraints = false | |
label.backgroundColor = UIColor.clear | |
label.textColor = light ? UIColor.white : UIColor.primary | |
label.font = UIFont.systemFont(ofSize: oversized ? 36 : 22, weight: UIFontWeightThin) | |
label.adjustsFontForContentSizeCategory = true | |
label.text = text | |
return label | |
} | |
} |
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
import UIKit | |
extension UITextField { | |
static func createDefault(_ placeholder: String?) -> UITextField { | |
let textField = UITextField() | |
textField.borderStyle = .roundedRect | |
textField.backgroundColor = UIColor.white | |
textField.placeholder = placeholder | |
textField.translatesAutoresizingMaskIntoConstraints = false | |
return textField | |
} | |
static func createPassword(_ placeholder: String?) -> UITextField { | |
let textField = createDefault(placeholder) | |
textField.isSecureTextEntry = true | |
return textField | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment