Michael Long
1 min readMar 27, 2020

--

While I agree that at some point in time we’ll all be doing declarative interface development using SwiftUI, this approach is extremely code heavy.

Be that as it may, my biggest issue with your examples lie in explicitly setting the heights of the various views. Why? Because doing so breaks dynamic font sizing and accessibility in iOS.

You can better support dynamic sizing by removing the height constraints, pinning the top and bottom views to the superview appropriately, and use content insets to add the appropriate padding to the text fields and button.

It’s best to NEVER to set the height of labels, fields and buttons and as such allow them to determine their own, best intrinsic content size based on device and user specified accessibility options.

BTW, the issue with translatesAutoresizingMaskIntoConstraints is that when you add the subview to the view iOS will automatically add its own set of constraints to the view based on the autoresizing mask and on the frame position and size you used when instantiating the view.

Since you effectively initialized each of your views with a frame size of CGRect.zero, their heights and widths were basically set to zero!

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

No responses yet