我正在Swift 中实现一个Circle
类(的子类),它根据传入的框架在其初始化程序中设置它,如下所示:UIView
radius
init(frame: CGRect)
override init(frame: CGRect)
{
radius = frame.width/2.0
super.init(frame: frame)
}
我还想确保从 Interface Builder 实例化圆的情况,所以我还实现了'required init(coder aDecoder: NSCoder)`(无论如何我都被 Xcode 强制执行)。
如何检索frame
以某种方式包含在aDecoder
. 我想要实现的基本上是这样的:
required init(coder aDecoder: NSCoder)
{
var theFrame = aDecoder.someHowRetrieveTheFramePropertyOfTheView // how can I achieve this?
radius = theFrame.width/2.0
super.init(coder: aDecoder)
}