【发布时间】:2016-08-11 15:50:52
【问题描述】:
我有一个UIButton 的子类:
class ColorButton: UIButton {
override func awakeFromNib() {
self.layer.backgroundColor = UIColor.blackColor().CGColor
self.layer.cornerRadius = frame.size.width / 2
self.clipsToBounds = true
}
}
在界面生成器中,我为按钮设置了 4 个约束:width = 100, height = 100, centerX, centerY。
当我在模拟器上运行我的代码时,该按钮消失。但是,如果它设置了
self.layer.cornerRadius = 50
它有效。我想不明白。如果有人理解这个问题,请告诉我。
【问题讨论】:
-
您在 awakeNIb 方法中的 frame.size.width 是多少?
-
frame.size.width 打印出来时返回 1000