My question is a simple one. In android, we can separate xml stylesheet from layout so that it can be reuse everywhere and edited easily for UI design change.
Is it also possible in iOS xcode? if can how (prefer if not from controller)? need libraries? what are good libraries for that?
Thank you for your answer.
Hipmunk UI/UX designer and iOS developer Danilo Campos explains it succinctly: "The very simple short answer is it's easier to make a good-looking, attractive iOS app compared to making an Android app." Design is built into Apple's DNA. Google's legacy, on the other hand, is search.
You could create your own styles using enums. By placing enums inside the Styles enum you get a nice grouping:
enum Styles {
enum Labels {
case Standard
case LargeText
func style(label: UILabel) {
switch self {
case .Standard:
label.font = UIFont.systemFontOfSize(12)
case .LargeText:
label.font = UIFont.systemFontOfSize(18)
}
}
}
enum Buttons {
case RedButton
func style(button: UIButton) {
switch self {
case .RedButton:
button.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)
}
}
}
}
Then you can use it like this:
Styles.Labels.Standard.style(yourLabel)
You can also then make extensions for the styles you have setup:
extension UILabel {
func style(style: Styles.Labels) {
style.style(self)
}
}
extension UIButton {
func style(style: Styles.Buttons) {
style.style(self)
}
}
And then use the extensions like this:
yourLabel.style(.Standard)
yourButton.style(.RedButton)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With