有没有办法创建像我希望 UIImage 具有的属性数组?因为我经常不得不做这种重复的模式(如果可能,我想去掉'userImage.layer'部分):
override func awakeFromNib() {
super.awakeFromNib()
userImage.contentMode = .scaleAspectFill
userImage.layer.borderWidth = 1
userImage.layer.masksToBounds = false
userImage.layer.borderColor = UIColor.red.cgColor
userImage.layer.cornerRadius = self.frame.height / 2
self.clipsToBounds = true
// Initialization code
}
答案 0 :(得分:1)
简短的回答是:没有官方支持的方式在 UIKit* 中对这些属性进行分组。
许多人最终在 UIKit 之上构建了一个薄的“样式层”。我见过的一些方法,从比较流行到不太流行:
* 有 UIAppearance,但不是每个属性或类都支持它。您通常可以查看头文件来弄清楚这一点。