UILabel not getting bigger with autolayout - ios

I'm using autolayout and my UILabel doesn't seem to get bigger when the app is opened on the iphone 6 and 6+. I have the following constraints on the label:
-Vertical spacing to top layout guide
-Vertical spacing to image below label
-Center horizontally in container
I also tried setting an aspect ratio constraint to itself and then a equal widths constraint with the parent view (with multiplier ratio) so that when the width of the parent view expands so would the label but no luck.
Are there settings that I should be implementing to allow this to happen? I thought labels have intrinsic sizing so they would get larger on their own as the parent view grows.

No, they have intrinsic sizing so they would get larger as their content grows (i.e. how much text they contain). That is what intrinsic sizing means. It means that the size is intrinsic.
Also, resizing a label physically (e.g. making it taller and wider) changes the size of the label. This will be evident if your label has a distinct colored background, for instance. It has no direct effect whatever, though, on the size of its text's font.

Related

iOS Stackview inside ScrollView with preserve image aspect ratio

I'm having a problem with scrollable content. Basically, I want to place one ImageView and one Label on the screen with ImageView width equals screen width. height depends on intrinsic content aspect ratio (while width is always equal screen width).
The label is 20 spacing bellow ImageView. That means whole content height may less or equal or even longer than the root view. What I have tried is to put Label and ImageView inside a StackView (ImageView has Aspectfit setting), Then put StackView inside ScrollView. Set up constraints as below.
The problem is the distance between ImageView and top Superview and between ImageView and Label is too big (ideally should be 20). Is there any way to achieve the desired outcome?
PS: I have tried to set stackView distributtion but no help
tl;dr Remove the aspect ratio constraint and add a height constraint for the UIImageView.
It’s important to understand that UIImageView is basically a container that holds an image, and its dimensions don’t necessarily reflect the image’s dimensions (unless you manually make them equal). When you selected Aspect Fit as UIImageView’s Content Mode, the size of the container didn’t change to correspond the image’s size; this setting only changed the way the image is placed inside the container.
As I can see in your screenshot, the UIImageView’s height is greater than its width; furthermore, the aspect ratio is fixed by the constraint you’ve added. When you placed a landscape-oriented image inside this container, the latter left white bars on the top and the bottom of the image (just like the black bars you see when you watch a widescreen video on an old monitor). Change Content Mode to Aspect Fill or Scale to Fill to see the actual size of the UIImageView.
To fix this, remove the aspect ratio constraint and set up a fixed height for either the UIImageView or the UIStackView. If I were you, I’d probably set the UIStackView’s height equal to Safe Area so that no matter how tall the stack view is, it doesn’t go beyond the screen boundaries.

How can I set the constraints?

I have a problem with my constraints.
I want to do something like this:
And I want the UIImage size (and labels) increases or decreases depending on the iPhone device used.
I tried using 'Aspect Radio', 'Equal Widths'... but I can not do that the size of the images are adjusted.
How can I set the constrains to do this?
Thank you!
You could put the labels and buttons inside a view the same size as your UIImageView. Set both views to Equal Width, then set the leading space constraint on the UIImageView, the trailing space constraint on the other view, and the space in between the two views. Finally, I would set an aspect ratio on each one so the height will stay proportional as the width is adjusted to different phone sizes.

Xcode Constraining UILabel vertically over a dynamic UIImageView

I am trying to constrain a label that is sitting on top a UIImageView. The ImageView keeps its aspect ratio for the different screen sizes so its length and width change according to the device.
I am running into an issue if I constrain the top of the label to the top of the image view at (for example) a constant of 58. For the lower resolution image that places the label where I want it visually. However on the higher resolution images that position is not where I want it visually. I have also tried adjusting the top constraint so that the constant is 0 and use the multiplier to adjust the position of the label. This however does not fix the problem and the label ends up at different locations on the image.
I really would not like to have to edit these constraints programmatically as I will have way more labels on different view controllers that would be a pain to program. Really hoping I can achieve this in IB.
I'm confused... why aren't you pinning a constant distance from the top of the label to the bottom of the image view?

Adjust UILabel size based on size Swift

I'm trying to adjust my label size based on screen size using swift. I'm using the dynamic layout and cannot figure it out. Essentially what I am looking to do is shrink the text/font size to fit within my frame.
You can do this all in the storyboard.
Add constraints between the leading and trailing edges of the label and its superview. (Something like |-[label]-| in the visual format.) This will adjust the width of the label as the width of its superview changes.
If you want the font size to adjust as well, you can set the Autoshrink item in the storyboard to Minimum Font Scale and set an appropriate value (0.5 is the default).

UIDatePicker min & max height

I have a UIDatePicker in my view with certain constraints on it. When looking at the iPhone 5/5s and 6, it looks fine. However, on the 4s and 6+, the minimum and maximum height of the datepicker destroys my layout. Is there any way of overriding these min/max values, or do you have any other suggestions for taking care of these situations?
Here's the constraints I have on the datepicker:
Align Center X to Superview
1:1 ratio
Bottom Space to View Equals: 33
Top Space to Label Equals: 5
Here's (my guess at) what happens:
When the DatePicker is placed on the screen, it tries to satisfy the top & bottom constraints. Then it sets the width to match the height. However, on the iPhone 6+, this height is too large, and it shrinks it to a maximum height. This creates large gaps in my design. On the 4s, it does the opposite: The height is too small, so it increases it. The DatePicker then overlaps my Label, and the space to the bottom View is too small. In both cases, the DatePicker ends up being not a square (!= 1:1).
Does anyone know if I can override these max/min values, or what I can do make sure it keeps its 1:1 ratio? And then fix the layout issues by shrinking the 33p bottom space constraint, but not the 5p top space constraint?
I managed to solve this by simply wrapping the UIDatePicker in a separate UIView with the same constraints, and then setting Clips subviews to YES.
Seems to be the only way of making the UIDatePicker a custom size, as it has certain bounds it conforms to.

Resources