I'm facing alignment issue when text input is multiple lines. In this example, first image shows left and right side text is properly shown. second image, it shows when we long text it takes 3 to 4 lines which disturb alignment on the left and right side as well.
I want to make left make independently size adjust which can maximum 5 line and right side remain as it is(no gap on top and bottom side).
Not sure if I understood your problem, but if you want to align the smaller text for example to the top you need to change HStack alignment top top instead of center, if this is not you problem, please explain it more with a sketch of what you need to achieve ๐
HStack(alignment: VerticalAlignment.top, spacing: 0)
Shown in second image, I want right side position to be always top. Right now, on left side it shows 3 line so itโs changing alignment on both side which is bad. Alignment only limits on left side
Related
Hi there I am currently trying to get the following Scene to scale correctly for any scene.
This is currently how it looks on a iPhone 7 Plus:
I managed to get it to scale the blue background correctly by adding the following constraints:
However, I don't know how to get the UIImageView, UITextField and UI Label to scale in the same way. I Want them to keep the same proportions as they have now on the iPhone 7 view. I have looked for youtube tutorials but none seem to show how to introduce a way to have these items scale as I want them to.
Any help is much appreciated, Thanks.
You can add constraints between UIImageViews, Labels, the window, etc. by holding control and clicking-and-dragging between two elements. For example,
UIImageView: add these constraints:
Vertical Spacing to Layout Guide (This constrains the top of the image to the top of the window)
Leading Space to Container Margin (Left side of image stays 'connected' to the left side of the window)
Trailing Space to Container Margin (Right side of image stays 'connected' to the right side of the window)
Vertical Spacing (vertical spacing between the image and the Label)
You can use this same idea to constrain the Label and Text Field to the left side of the window and to keep the vertical spacing between the UIImageView, Label, and Text Field consistent on all devices.
I'm just getting started with iOS development, and I'm following a series for making a game.
I want to align the circle (see screenshot) but there is no constraint for left
How can I make sure it aligns left for example on the iPhone 4 (see screenshot).
Xcode version (7.3.1 (7D1014))
Option 1: Hold control button, drag to the left and select `Leading spaces to container. The object that you are defining the space from should be highlighted. You should get the following menu:
Option 2:
1. Select the object
2. Press the pin button
3. Set the distance from the frame
4. Pressed the red button
5. Select Add constraints
Leading is left, and Trailing is right
First step, the most important one :
Remove that circle, and make sure your view has no constraint exception (look at the debugger) and that everything is where it should, on all phones. Ff that is correct, move on to the next steps.
Technically you should just be using Left or Leading, they're almost identical. (Leading is actually different, it'll align to the right in Arabic localized phones for example).
So what you wanna do is make sure your view has all its constraints set correctly, obviously, and for what I'm looking at you just need Top, Bottom Left and Right (or Leading and Trailing).
Just drag & drop from the circle to the view that is supposed to be the "anchor". For example, I'm guessing your top left circle will have its Left constraint going against the border of the view, and Top/Right/Bottom will be against the black bars. Easy.
For the left, drag & drop between the circle and the superview (the uppermost view in the hierarchy) and select Left/Leading. Then select the constraint and look at the properties.
Look at the image I have as an example. If you see the constraint properties on the right, I'm saying :
First item = "The leading side of my message box"
Relation = Should be equal (in distance)
Second Item = To the leading side of the Header label
Its plain english, the left side should align to the left side.
Your case is similar, you want the left side of your Image to be aligned with the left side of the View !
Now the 3 others constraints are sliiiiightly different, because you don't want Right-on-Right, Top-on-Top and Bottom-on-Bottom.
You actually need the Bottom of your circle to be aligned with the Top of the view under it, the Right of your circle to be aligned with the Left of the view on its right, and the top of the circle to be aligned with the bottom of the top bar.
Following?
Now you can adjust these constraints, you have a "Constant". This is the distance that the "Equal" refers to. If you say "the distance between this and that should be equal to zero", the two views will be sticking together. So usually you can add some margin.
Important note ! If you use the drop down for each Item (first and Second), you will see you can tick/untick margins ! This is important, it automatically adds Apple-advised margins, which is a value of 8, that is counted on top of the Constant value. So if you HAVE a margin and a constant of 0, you actually have a spacing of 8. This is to make your life easier because you'll usually have many margins and its easier to count from zero.
Any question?
I've got a label we'll call selectedTextLabel with multiple labels underneath it forming a list (yes, I know about repeaters), when I select one of the lower labels I throw in that label's text description into selectTextLabel. The problem I've running into is that, though selectedTextLabel is aligned center (positionally) and the text within it is center aligned, when new text that is longer or shorter than the original gets put within it from an action, it keeps the same top left xy coordinants and increases or decreases the width accordingly making my design look misaligned.
It's almost like it's not obeying text-align: center on dynamic text like it does in the editor.
Does anyone know a solution? Is this a bug? I've googled but only have gotten editor based answers as opposed to dynamic browser based answers.
Thanks.
After an insight, it turns out it's rather easy. You just have to make the label the full width that you want it to be centered within. Then if you have text align center set, it'll keep the text centered.
What was happening in my instance was that I only had the label set to the width of the first selection and since the label didn't know what to do when something longer was set as the text, it expanded it's width but kept the same top left x and y coordinants, making the new center misaligned.
I hope this helps someone out there.
I found another stackoverflow post asking about essentially the exact same thing I am trying to solve (iOS Autolayout how to stretch 2 button horizontally), however I am still having issues figuring out how to go about aligning the edge of my object to the center of the superview. I need my two buttons to be aligned side-by-side just as in the example in the post I linked, but I cannot figure out how to reference the center of the superview to set my alignment to it, like is shown in the screenshots. Could someone provide a little more insight as to how to achieve the result mentioned in the linked post? Thank you so much.
One way is to set the pin the left button to the left edge. Right button to the right edge, Pin the left side of the right button to the right side of the left button. Then set their widths equal. This is the easiest way for me if I'm using storyboard.
Make sure the constraint between the two buttons has a constant of 0 or however much space you want between them.
If you take a look at this screenshot it will click that button when its red or yellow it will tell you what constraints you are missing on a button.
If a view is misplaced simply hit the view and press cmd+option+"=" and it will give you a preview based on the constraints you've placed on it.
i am working on an iOS project and want my 2 views to be vertically aligned with respect to each other as shown in attached image.
There is an image view on left and a view on right side. The right side view contains some labels in it. I am using autolayouts and have properly applied constraints to image view (i.e. top/leading/height/width).
Now i want my right view to be center aligned (vertically) to thumbnail but when i do this, it asks for missing constraint y position. I don't know how to fix that (i can not add top/bottom constraint as my title label can have 1 or 2 lined text and the right side view will grow accordingly)
Is it possible to achieve this? if yes, then how? Thanks.
It's a tableView basically. Above image is for detailed description. Whereas, design should be like the following (right side view should be centered aligned to left side image)