iOS development-Content hugging priority & content compression resistance priority

Source: Internet
Author: User

1. What is content hugging priority

You can think of it as a rubber band placed on the view.

This rubber band organizes the view beyond its intrinsic size (intrinsic content size).

It has a priority, from 0 to 1000.

1000 indicates that the view must never exceed intrinsic content size.

Let's look at an example:

There are two horizontally arranged label controls (labels), and you've set up the constraints as well.

This will work fine until the parent view becomes wider.

So, here's the problem.

If the parent view becomes wider, should the label be wider?

This is when we use content hugging priority.

View controls that have high-priority content hugging priorities will not be stretched.

You can think of this priority as the tensile strength of a rubber band.

The larger the priority, the more the view will want to maintain its intrinsic size (intrinsic content size).

2. Content Compression Resistance priority

Contrary to content hugging priority, the content compression resistance priority is used to resist compression.

In short, the former we have discussed is the resistance to stretching, that is, the resistance to become larger, and the latter is to resist compression, that is, the resistance becomes smaller.

In the example above, when the parent view becomes smaller, the label with the high priority will not be compressed, so the text on the label is not truncated.

iOS development-Content hugging priority & content compression resistance priority

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.