Reputation: 15599
Search a bit but could not find a solution. Suppose I have a label and a text field. I want the textfield to be aligned 10 pixel to the right of middle of its superview having a width of half of superview - 20 pixel. i.e. 10 px gap in both side. How can I achieve that in storyboard? Is it possible or I have write code for that? Similarly Label is half of superview - 20 px width. Left aligned. 10 px left gap.
Upvotes: 1
Views: 1728
Reputation: 3873
If I understand you correctly, you want this with both views having the same width?
|-10-[UILabel]-20-[UITextField]-10-|
Then one way to go about this is to create constraints for
UILabel
UILabel
and UITextField
UITextField
UILabel
and UITextField
Upvotes: 2
Reputation: 2107
I want the textfield to be aligned 10 pixel to the right of middle of its superview That could be done like that:
Horizontal centering constraint with offset to the right.
having a width of half of superview - 20 pixel. i.e. 10 px gap in both side.
To achieve that you should select your parent view and your subview(in your case, the text field) by holding the command key and left-clicking both you view and the text field. See the image below:
Having those two selected, click the Pin button at the bottom of the IB editor area and make all as illustrated below:
Then, go to the inspector area of either your parent view or your text field and make it be like (the image is captured from the text field's inspector). And notice: you should select the equal width constraint and type the values manually. When you change the multiplier from 1 to 0.5, the constraint will become of type "proportional width" and that is what you are eager for.
Upvotes: 5
Reputation: 14040
if i got you right this is totally possible in storyboard. setup the following constraints:
hope i got you right :)
Upvotes: 1