我的问题很简单。在android中,我们可以将xml样式表与布局分离,以便它可以在任何地方重用,并且可以轻松编辑以更改UI设计。
iOS xcode 中也可以吗?如果可以如何(如果不是来自控制器则更好)?需要图书馆吗?有哪些好的库?
谢谢您的回答。
您可以使用枚举创建自己的样式。通过将枚举放入 Styles 枚举中,您可以得到一个很好的分组:
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)
}
}
}
}
然后你可以像这样使用它:
Styles.Labels.Standard.style(yourLabel)
然后,您还可以对您设置的样式进行扩展:
extension UILabel {
func style(style: Styles.Labels) {
style.style(self)
}
}
extension UIButton {
func style(style: Styles.Buttons) {
style.style(self)
}
}
然后使用这样的扩展:
yourLabel.style(.Standard)
yourButton.style(.RedButton)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)