I have designed two labels side by side i have given left side label 150 fixed width, why alternatively getting below warning.
For above image left label i have given constant text and constraints like below
fixed width = 150, top = 10, leading = 10 , height = 30
for right label text will come from json and constraints like below
top = 10, leading = 10, trailing = 10, height = 30
i have highlighted all my left side fixed width labels, here for all labels i got below warning
Main.storyboard Fixed width constraints may cause clipping
but here if i select first label warning and if give greater then or equal and horizontal hugging from 251 to 250 then warning disappears.. like same if i do for second label then it becomes big like below
for third label if i give greater then or equal then warning disappears.. like alternatively warning disappears why, you can see that in top image. why its happening like this, how to clear all my warnings. please help me.
1.Give the left sided labels horizontal content hugging priority of 252.
2.Give the right sided labels horizontal content hugging priority of 251.
3.Give horizontal spacing of 8 between the left sided and right sided labels.
4.Remove fixed widths for all labels.
5.Align leading and trailing of all the left sided labels and just the trailing of all the right sided labels.
6.Give vertical space to left sided label from right sided label of the previous row.
7.Vertically center align the left sided and right sided label in the same row.
All your warnings will disappear.
Related
I have a UILabel with the following constraints:
- Align Center Y to Superview (priority 750)
- Top Space to View, greater than equal to 0 (priority 1000)
In normal mode, the UILabel is align center to Y which is ok. But if I go to Accessibility setting and set to large fonts (maximum size) I want my label to use the Top Space with greater than equal value.
Right now is still using the Align Center to Y in both cases. Is there a way when the font is large to use the other constraint with higher priority ?
PS: below this label there are 2 other labels which get shrunk when font is large, because top view label stays in the middle of screen instead of moving up.
Try this
- Bottom space to view, equal to zero (multiplier 2)
- Top Space to View, greater than equal to 0
Screenshots
Project - https://github.com/leninsmannath/AutoLayoutBottomFromCenter.git
I am giving leading align constraint for two label. When text in both the lebel is same both liked aligned properly. But if text is different they don't look aligned (Difference of 1 Pixel is coming), is there any constraint, that work independently of text.??
In my storyboard, my view controller has two container views as shown below
The second container view is it tone am having difficulty setting constraints for.
When I actually run the app, the text field, becomes very narrow. My horizontal constraints are obviously incorrect but I can't figure out the right settings.
Here what I currently have:
FilterIcon - trailing space to superview (right): 0
- Align Center Y
- Leading space to "Go": 16
- Equal height to text box
Go Button - align center Y
- trailing space to filter icon: 16
- leading space to text box: 8
Text Box - leading space to superview (left): 0
- trailing space to Go Button: 8
- equal height to Filter icon
- horizontal hugging priority: highest of 3 elements 751
I thought the text box would expand from the left margin until it reached the Go box which is set to the right based on the filter icon.
Instead I get this result:
What am I missing for the constraints?
How about configuring like this?
Text Box
leading space to superview (left): 0
trailing space to Go Button: 8
equal height to Filter icon
horizontal compression priority: 752
Go Button
align center Y
trailing space to filter icon: 16
leading space to text box: 8
horizontal hugging priority: 251
Filter Icon
horizontal hugging priority: 251
Align Center Y
Leading space to "Go": 16
Equal height to text box
Here is my screenshot.
If you don't want to set priorities, you can just set width constraints for both Filter Icon and Go Button. For more information, there is very good tutorial about content hugging priority and compression resistance priority in here
I think you can set both buttons' height equal to width. Then other space is left to the text field.
Give aspect ratio to the text field for its width and height and give center y to superview. This will definitely work. But make sure when you give aspect ratio, your text field is having the width you require.
I have one label to the right side of parent view.On top of label there is a view.I have given below constraints to label.
Align leading to top view (constant<16) LOW PRIORITY
Top space from parent view
Trailing space to parent view (constant=28) HIGH PRIORITY
I want when text inside the label increase it should change it's position.it should move towards left but at the same time it should also move towards right.I mean should increase it's width in both directions.As of now it's only moving towards left & keeping fix position from right.
Please tell how can i achieve this task?
i think if you set center alignment for label alignment you should get answer you want.Also give same priority to leading and trailing.
This will not work as the trailing space to super view constraint will most likely always win, as you have observed.
The width and height of the label is taken care of by its intrinsic content size and hence no constraints are needed for that. As far as position goes, the y is taken care of by the top space constraint. Finally the x will need a constraint that will allow it to grow in both directions as mentioned. To enable this behaviour remove the leading and trailing constraints and add a horizontally centered constraint. This will centre the label to its super views centre. To offset the position left or right you may choose a constant value or use the multiplier property.
The multiplier is good for positioning a certain percentage of the superview regardless of its size. e.g.: if the superview is the root view then a multiplier value of 0.5 places the label quarter of the way across the view, 1.0 makes the centre x align exactly, 1.5 makes it 3/4 across from the left.
here some points about using autolayout that I don't understand.
1/ I have set a constraint on the leading space and the trailing space of a label (so the horizontal size of the label should be adjusted automatically) but the label fit the size of the text. How to not autosize the label (I have seen hundreds of posts about autofit a label but nothing about not autofit).
2/ Concerning my UIScrollview, I have set up trailing space and leading space to 0 (so it should fit all the screen whatever the iPhone display size) but some margins still appears. Why ?
Thanks for your help.