I am using Apple Tutorial "Start Developing iOS Apps (Swift) - implement a custom control, with Xcode 8 and Swift 3. I am doing "Declare a Constant for the Button Size" section but getting an error. Apple suggests that we use the following code.
override func intrinsicContentSize() -> CGSize {
let buttonSize = Int(frame.size.height)
let width = (buttonSize * starCount) + (spacing * (starCount - 1))
return CGSize(width: width, height: buttonSize)
}
But, the first error (which is sort of irrelevant to this question) is that in Swift 3, intrinsicContentSize() has been changed to invalidateIntrinsicContentSize(). After using override func invalidateIntrinsicContentSize() I get the following error.
swift:53:19: Method does not override any method from its superclass
When I remove override, I get the following error.
53:10: Method 'invalidateIntrinsicContentSize()' with Objective-C selector
'invalidateIntrinsicContentSize' conflicts with method
'invalidateIntrinsicContentSize()' from superclass 'UIView' with the
same Objective-C selector
Can anyone please explain what might be going wrong? What can I change or add to get rid of this error?
Thanks
In Swift3, it has been changed to a property and its not available to you as a method. You should override the getter to return your desired size:
override public var intrinsicContentSize: CGSize {
return CGSize()//your desired size here
}
Please refer to the documents IntrinsicContentSize
迅速,internalContentSize已更改为存储属性,而不是invalidateIntrinsicContentSize(),因此您应尝试覆盖var intrinsicContentSize
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.