benjanisa benjanisa - 1 year ago 121
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

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download