iOS — content hugging and content compression resistance priorities

Priorities are very much important when dealing with autolayout. Every constraint has a priority. It is just a number ranges from 0–1000 .

STOCKSNAP.IO
Intrinsic content size (Apple docs)

Content hugging priority:

Sets the priority with which a view resists being made larger than its intrinsic size. Setting a larger value to this priority indicates that we don’t want the view to grow larger than its content.

horizontal content hugging priority: green(251)- blue(251)
horizontal content hugging priority: green(250)- blue(251)
horizontal content hugging priority: green(252)- blue(251)

Content compression resistance priority:

Sets the priority with which a view resists being made smaller than its intrinsic size. Setting a higher value means that we don’t want the view to shrink smaller than the intrinsic content size.

Button horizontal compression resistance priority is 750 and button width constraint priority is 1000
Button horizontal compression resistance priority is 1000 and button width constraint priority is 999

That’s it. !

Enjoy!!

If you enjoyed reading this post, please share and give some claps so others can find it 👏👏👏👏👏 !!!!

You can follow me on Medium for fresh articles. Also, connect with me on LinkedIn and Twitter.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store