如何更改多个UI元素的属性

时间:2016-04-22 14:11:05

标签: swift user-interface uikit

我正在尝试制作一组​​<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>Your Main Class</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> s粗体,并认为它可以用类似CSS类来完成。我想到的唯一方法是继承UILabel并将其作为自定义类添加到每个标签:

UILabel

但是这给出了一个错误“带有Objective-C选择器'字体'的'getter'字体'与来自超类'UILabel'并使用相同的Objective-C选择器的'font'的getter冲突”。那么有没有办法像这样做,或者以不同的方式轻松制作一堆标签的字体粗体?

1 个答案:

答案 0 :(得分:2)

import UIKit

class BoldLabel: UILabel {

//This method is call when you affect this class to a UILabel in your STORYBOARD
required init?(coder aDecoder: NSCoder) {
    super.init(coder:aDecoder)
    self.setup()
}

//This method is call when you programatically create an instance of this UILabel class
override init(frame:CGRect) {
    super.init(frame:frame)
    self.setup()
}

func setup() {
    //All custom properties of this label class here
    self.font = UIFont.boldSystemFontOfSize(28)
}
}

故事板中UILabels的结果:

enter image description here