Using Auto Layout, how do I make two labels on the same “line” be dynamic in their widths (adjusting with how wide each one needs to be)?
Say I have two UILabels, one is a URL and one is a timer:
[http://website.com/link/to/specific/story] [9m 42s]
But the “timer” UILabel changes width a lot. Sometimes it is just
12s for example, other times it is
125h 32m 8s. There’s a lot of variability. I want the timer UILabel to take up as much width as it needs and the URL label to take up the rest. This means if the timer is longer, shorter URLs, etc.
How do I do this in Auto Layout? Preferably in Interface Builder?
- Unable to use autolayout constraints in a tableview
- How to use auto-layout to move other views when a view is hidden?
- Resize the screen when keyboard appears
- Adding priority to layout constraints
- bug in UITableView layout after orientation change
- Adding a dynamically sized view (height) to a UIScrollView with Auto Layout
2 Solutions Collect From Internet About “Using Auto Layout, how do I make two labels on the same “line” be dynamic in their widths (adjusting with how wide each one needs to be)?”
You should set the compression resistance, URL label must have lower value;
Set the horizontal space between labels to constant (for example zero or default);
Set width for each label and select “less than” or “greater that” relation, these values set limits for shrinking/expanding of the view.
This is where compression resistance becomes important. Since the URL label needs to shrink first (in order to accommodate the space for the timer label), the compression resistance of the URL label should be lower than the compression resistance of the timer label (in horizontal direction, of course). You can easily set this attribute in IB.
- How to tell Xcode where my info.plist and .pch files are
- iOS Game Center: Scores not showing on leaderboard in sandbox
- CloudKit – NSPredicate for finding all records that contain specified CKReference in a reference list
- Xcode does not find C++ static library
- Adding a view to the window hierarchy
- Disable Vibration iphone
- iOS equivalent to Android Service?
- open file from local file system with default application iOS
- IOS maximum volume level for AVAudioPlayer?
- Upload IPA, strange issue: ERROR ITMS-90032:“Invalid Image Path – No image found at the path referenced under key '$key': '$path'
- fbauth2 is missing from your Info.plist under LSApplicationQueriesSchemes and is required for iOS 9.0
- Can XCode 3.2 run on 10.5 Leopard?
- Xcode Interface Builder – “correct” way to delete/rename miswired IBoutlets / IBactions
- NSDictionary: method only defined for abstract class. My app crashed
- how to mask an unwanted “Dead Store” warning in XCode?