Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios drawRect()之后是什么_Ios_Swift - Fatal编程技术网

Ios drawRect()之后是什么

Ios drawRect()之后是什么,ios,swift,Ios,Swift,我想知道在调用UIView的drawRect()之后如何执行代码 iOS渲染周期中是否有afterdrawRect挂钩/方法 为什么?? 我想在InterfaceBuilder中显示一个按钮(通过IBDesignable),但在最终产品中隐藏它 @IBDesignable class FakeUIButton: UIButton { @IBInspectable var fillColor: UIColor = UIColor.purpleColor() { didSe

我想知道在调用UIView的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
    }

}
你可以用

prepareForInterfaceBuilder()
#if !TARGET_INTERFACE_BUILDER
    // this code will run in the app itself
#else
    // this code will execute only in IB
#endif
要准备在IB中显示视图,此中的代码不会在应用程序本身中运行。 或者你可以使用

prepareForInterfaceBuilder()
#if !TARGET_INTERFACE_BUILDER
    // this code will run in the app itself
#else
    // this code will execute only in IB
#endif

要仅运行代码,当在IB中显示时。

您可以在ViewDidLoad中隐藏按钮。您可以解释为什么要在IB中显示按钮,但在运行时隐藏它吗?要有某种“热点”,请在后台仅使用JPG构建快速原型。我在上面添加了代码。