Matt Spoon Matt Spoon -4 years ago 199
iOS Question

Finding the size of a view adjusted by a UIStackView swift

A number of views in a

are adjusted to fit the stack. The views are initialised with no frame because they are resized by the stack view. Is there a way which I can get the size of the views after they have been resized by the stack view?

Answer Source

The sizes are available after UIStackView.layoutSubviews() finishes. You can subclass UIStackView and override layoutSubviews:

class MyStackView: UIStackView {
    override func layoutSubviews() {
        print("arrangedSubviews now have correct frames")
        // Post a notification...
        // Call a method on an outlet...
        // etc.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download