How can I have one element align to the left and another one centered in Vaadin HorizontalLayout? - vaadin

I wanna center my Label component in Horizontal Layout (I'm working on navigation bar) but I still want to have hamburger menu button aligned to the left side of the screen,
I tried to use
navbar.setComponentAlignment(myLabel, Alignment.MIDDLE_CENTER);
on my Horizontal Layout but this don't work, it only center in verticaly,
What can I do to achive that?

Vaadin Label is by default 100% wide, so you need to set its width to undefined to center it:
myLabel.setWidthUndefined();
Of course, your HorizontalLayout must be 100% wide (it's undefined by default).

Related

Xcode 8.1 Auto Layout

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.

Center align a view vertically to other (sibling) view iOS

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)

Align button with respect to background image in XCode

I have a background image and I need to put buttons in it. I have tried auto layout as well by fixing it's height and width (The button text was not part of the background, has been added manually), but it is not working for all screen sizes. I want two buttons equidistant from line that can be seen(like in iPhone 4 inch screenshot, line is part of the background). How can I go about doing that? Are there any other tools which might be helpful? I am using swift
Best way to do this is to add a hidden view which has a background color of clear. Add a constraint for this which centers it horizontally and a constraint which positions its top where you want it.
Make the width of this transparent view the space you wish between buttons or leave it as 1 wide if you wish and use offsets in the constraints described below instead. Make the height 1 so it takes up no space.
For the buttons align the top of the buttons with the bottom of the transparent view. This places the buttons vertically.
Finally pin the trailing edge of button 1 to the leading edge of the transparent view and pin the leading edge of button 2 to the trailing edge of the transparent view. Set the offset for the pins to be the distance you want the buttons from center if you gave your transparent view no width.
On all screen sizes, the buttons will now be relative to the center.
If you want to have them equally space out, you can add transparent views to the left and right of the buttons and pin them together so they act like spacers. So superview->spacer->button->spacer->button->spacer->superview.
Using the spacer approach, select the 3 transparent views and add a constraint for equal width. You buttons will now be spread apart equally.

Autolayout, retaining button spacing for larger screens

I have a setup like this in the interface builder:
(iphone5 size). I want the buttons to stay in that layout if the screen size increases i.e widens (but the buttons stay the same size). If I pin the top two buttons to their respective container edges when the screen is larger they will be too far apart from each other. I have the bottom button increasing its size fine. How can I do this? I tried putting a transparent UIView between each button and the container edge, but couldn't get it working this way. Could someone give me a pointer on how to do this please? thanks!
Assuming you already have the width, height and y-constraints in place, to create the correct x-constraints you can try something along the lines of this:
check the Horizontal Center in Container option
choose your button and double click the newly created constraint Align Center X to
change the Second Item from Center X to Trailing
enter a constant value to offset the position
Do this for both buttons. The constant value of the second button should be the negative of the first one AND its Second Item should be Leading.
Result
This method will result in equal spacing on all size classes.
The only drawback is that the spacing is no dynamic. for that purpose you would need some placeholder view in between.
I would say there are two approaches you could take:
Assumption is buttons have constraints for width and height.
1) Use a transparent view which you center horizontally within its containing view. Then pin the left buttons trailing edge to the transparent view and the right buttons leading edge to the center. You have a choice as to how to define their vertical position.
or
2) Add a transparent container view to your main view and then move your two buttons inside this view. Pin the two buttons apart the desired width and then pin the other button edges to the containing view at size 0pts. Finally center the new containing view horizontally in the view. You will need to define the height of this container view from the top or bottom.
The second is probably easier to execute within storyboard.

Using size classes, auto layout and build for iOS7 in Interface Builder

Is there a way to use Interface Builder to maximize a view for the w:Any h:Any size classes without relying on iOS8 only features?
I'm trying to have a simple scrollview inside a navigation controller and a tab bar with some horizontal centered labels. But I can't even get the scrollview to be maximized without getting layout attributes relative to the layout margin or misplaced view warnings.
I dragged the scrollview across the canvas between navigation bar and tab bar.
I set contraints of the scrollview to center alignment Y and X and vertical space at the top to take in account of the navigationbar.
Now when I try to add a contraint to have the bottom next to the navigationbar I get the iOS 8.0 warning.
Also I don't understand what width and height I need to set when I want the object to be dynamically maximized depending on the device or orientation - I thought that was the point of auto layout.
As Riley pointed out this question/answer helped me to get started.
Also specifically to my scrollview problem I needed to make the following constraints:
vertical space top and bottom, horizontal space left and right, center x alignment and most importantly don't use the checkbox "constrain to margin" which is only available for iOS8+.

Resources