How can I set the cornerRadius of a UIStackView?

WallyAmerica picture WallyAmerica · Nov 26, 2015 · Viewed 15.5k times · Source

I'm updating my app to use UIStackViews, now that most people should have updated to iOS 9.

In the old version, I made a UIView consisting of two UITextFields and set its layer.cornerRadius property.

In the new version, I created a UIStackView consisting of the same two UITextFields, instead of the UIView. When I try setting its layer.cornerRadius property nothing seems to happen. The documentation doesn't seem to have any helpful/relevant information.

Answer

ZHZ picture ZHZ · Nov 26, 2015

UIStackView just manages the position and size of its arranged views, the cornerRadius has no effect. Try to add a custom view below the stackView and set the cornerRadius of it.