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?
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.
- Why isn’t my weak reference cleared right after the strong ones are gone?
- iAd in xcode 6 with Swift
- Xcode 8.1 Push Notifications in swift 2.3 with firebase integration not getting?
- cancel dispatch_after() method?
- How to simulate protected properties and methods in objective-c
- Remove white space from contact number fetched from phone book
- how to get the path of the image which is in iphone gallery
- how to prevent NSJSONSerialization from adding extra escapes in URL
- Link Errors with Parse.framework iOS
- Resize UITableView Header AND containing UITextView (iOS7 + AutoLayout)
- Phonegap App : External URL don't open in InApp Browser of IOS
- what does -arrayWithArray actually DO?
- Removing in app purchases from a new version of the application(iOS)
- Timer decrement gets varied for each page load
- Detect if wifi is turned on