我想要得到我的自定義UIButton的真正高度。但我總是得到比我預期的更小的價值。我得到大約30個的東西,但預計一些關於45UIButton,Autolayout並獲得按鈕的高度
override func awakeFromNib() {
print(self.frame.height)
self.layer.cornerRadius = self.layout.frame.height/2.0
self.clipsToBounds = true
self.titleLabel?.adjustsFontSizeToFitWidth = true
}
這是我的代碼,但在運行時莫名其妙的自動版式改變大小,這是完美的,但我不能設置正確的cornerRadius(總是太小)。所以也許我需要乘數或類似的東西。我已經嘗試添加頂部和底部的contentEdgeInsets,但它沒有任何區別。
感謝 托比亞斯
調用layoutIfNeeded()!謝謝! – Tobias