-1
我想知道如何執行UIView的drawRect()被調用後的代碼?什麼後drawRect()
在iOS渲染週期中是否存在afterdrawRect掛鉤/方法?
爲什麼? 我想在InterfaceBuilder中顯示一個按鈕(通過IBDesignable),但將其隱藏在最終產品中。
@IBDesignable class FakeUIButton: UIButton {
@IBInspectable var fillColor: UIColor = UIColor.purpleColor() {
didSet {
layer.backgroundColor = fillColor.CGColor
self.alpha = 0.5
}
}
override func drawRect(rect: CGRect) {
layer.backgroundColor = fillColor.CGColor
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func layoutSubviews() {
super.layoutSubviews()
self.backgroundColor = UIColor.clearColor() // called to late in render cycle
}
}
你可以在viewDidLoad中隱藏按鈕 – SolaWing 2015-03-25 11:47:30
你能解釋爲什麼你想在IB中顯示一個按鈕,但在運行時隱藏它嗎? – sbooth 2015-03-25 11:48:05
爲了讓某種「熱點」在後臺創建一個只有jpgs的快速原型。我添加了上面的代碼。 – fabian 2015-03-25 11:53:38