Reputation: 25
I'm new to iOS programming. I was following this tutorial, but I have a problem with the intrinsicContentSize() function. I wrote this code:
override func intrinsicContentSize() -> CGSize {
let buttonSize = Int(frame.size.height)
let width = (buttonSize * starCount) + (spacing * (starCount - 1))
return CGSize(width: width, height: buttonSize)
}
It belongs to a custom class that I created to make a custom view (it's a control that must handle a five-star rating). The problem is that frame.size.height gives a 0 value, so the view is not displayed on the screen. So, where is the problem? I have copied the code from the tutorial, you can check it if you go under "Implement a custom control" and then to "Declare a Constant for the Button Size". I'm using Xcode beta, so swift version is 3.0, while the tutorial is for swift 2.3, could this be a problem?
Upvotes: 1
Views: 1040
Reputation: 21
I ran into this issue as well. intrinsicContentSize() has been changed to a property so you'd override it like this:
override var intrinsicContentSize: CGSize {
let buttonSize = Int(frame.height)
let width = (buttonSize * starCount) + (spacing * (starCount - 1))
return CGSize(width: width, height: buttonSize)
}
Upvotes: 2
Reputation: 313
Did you use StackView in your project? Check the image bellow:
Upvotes: 0