Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:43:06+00:00 2026-06-16T01:43:06+00:00

I am attempting to build a dynamic layout using the new autolayout api in

  • 0

I am attempting to build a dynamic layout using the new autolayout api in iOS 6.0. The layout that I am attempting to build has 2 buttons with a label inbetween them as shown in the image below:

enter image description here

What I would like is for the container view shown in grey to increase or decrease in size depending on the amount of text in the label.

So far I’ve managed to get the layout to work exactly as described with one small issue that I’ve not been able to resolve. The problem I am having is that the intrinsic height of the label is alway calculated with the original width of the label (e.g. the one set in interface builder) and not the width of the label that is set from the constraints I have on it.

The constraints that I have on the views are as follows:

  • H:|-[leftButton]-[label]-[rightButton]-|
  • Both buttons are centered Vertically
  • V: |-[label]-|
  • the content hugging priority of the buttons is higher than the label
  • the compression Resistance of the label is higher than the container view

All of these constraints together create the desired layout.

However:

  • If the Width of the label in interface builder (the literal size in interface builder) is less than the width of the view at runtime, then the height of the container is too large.

enter image description here

To help clarify this, the IB view of the above layout was as follows (note much narrower)

enter image description here

  • If the Width of the label in interface builder (the literal size in interface builder) is greater than the width of the view at runtime, then the height of the container is too small and lines of text get cut off.

What appears to be happening is that although there is no constraint on the labels width, the label seems to calculate its height (and thus the autolayout calculated height of the container) based on the original width of the label when it was created. However whats so strange is that the text appears to be the correct width and height but the label itself has a frame thats just too big or small.

I guess this is related to the order in which things are happening, and have tried calling updateConstraintsIfNeeded in the containerViews layoutSubview method however this doesn’t appear to do anything.

Any suggestions would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:43:07+00:00Added an answer on June 16, 2026 at 1:43 am

    May be I am late but any way I’ve found solution. Any time when label width is changed you need to manually update preferredMaxLayoutWidth for Label. For example:

    Label.preferredMaxLayoutWidth = 200;
    

    Interface builder sets preferredMaxLayoutWidth with initial label width.
    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to build some dynamic menus that are created on the fly by
I'm attempting to create a dynamic map using the latest Google Map API. Everything
I am attempting to build an authentication mechanism using API keys for access. As
Attempting to build a C# project which has numerous references to assemblies in NuGet
I'm attempting to build a method call from strings that have been passed into
I'm attempting to build a JSF/Hibernate application using Java 7 and Tomcat 7. I
I am attempting to build a backup script that moves a tar file from
I'm attempting to build an app using the Sencha Touch 2 builder tools. I
I'm attempting to build Python 2.6.2 from source on my Linux system. It has
I'm attempting to build some C++ code that requires the Windows 7.0 SDK header

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.