COOKIES COOKIES - 3 years ago 215
iOS Question

Minimum width for view when label is controlling width

I’ve been trying to do the following for quite some time without success.. I’m super grateful for any advice or tips.

Imagine having a

that has a fixed height and that’s horizontal/vertical in whatever superview it’s implemented in. Imagine that the view has a
that controls its width.

How can you now set a minimum width for that
? Just in case the
is empty or has a 2 character string, I’d like the
to have at least 50 pix width.

Here's a visual example:

Visual example

Imagine the UILabel having no text. Then the UIView would have 0 width. That's the problem I'm trying to solve.

Answer Source

Create a width constraint with the minimum required width for the UIView and change the relation from Equal to Greater Than or Equal. enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download