benjanisa benjanisa - 3 months ago 33
iOS Question

XCode: Stack View breaking with custom control

I am looking to layout multiple components in a stack view. The layout is working perfectly until I add a custom control, which is removing all elements below it in the stack. I'm not sure what could be causing this (perhaps it's from constraints?), any ideas would be appreciated!

Storyboard (the custom control is "Rating Control", in between the Name Text Field and the Photo Image View):


Simulator without custom control:

Simulator without custom control

Simulator with custom control:

Simulator with custom control


This was caused by the following function in my custom control:

override var intrinsicContentSize : CGSize {
    let buttonSize = Int(frame.size.height)
    let width = (buttonSize + spacing) * stars

    return CGSize(width: width, height: buttonSize)