I have to show the Name and EmailID aligned horizontally properly with the Profile Image . So that the Name and email ID appears exactlybat the center of the UIImageView.
But you can see the name and email id are not in centre with the profile image. Why is this happening? I have given the following constraints:
Remove leading and trailing Constrain and set align center x to imageView.
You can also set leading and trailing Constrain. but both are equal as follow.
Just control+drag from label to imageview and select Center Horizontally.
Ctrl drag from the labels to the imageview and choose Center horizontally.
I know the question has been answered but this is best solution horizontal stack view
Ctrl+drag from image and labels to their superview and select Center Horizontally in Container.
Using AutoResizing Tool:
Step1: Place your image view and labels exactly how do you needed.
Step2: Select Image view and click on Size Inspector.
Step3: Simply click on red bars of autoresizing subview to de-select it which is shown in below image.
Step4: Repeat same steps for labels. I made labels text alignment as centre.
Related
I have a simple UIImageView with 50x50 size.
If I had a UIView of size 100x100 and I wanted to center the image inside of it, all I have to do is set these
But how do I do the same with a UIStackView of size 100x100?
EDIT i think i should have been more clear. The questions is, how do i center the image both vertically & horizontally inside of the UIStackview ?
Use two stack views.
Vertical stack view with centre alignment.
Inside that is a horizontal stack view with centre alignment t.
Inside that is your image.
You need to set the alignment to center inside attribute inspector of UIStackView
Check attribute inspector for stackview settings:
follow these steps.
1) drag Uiimageview.
2) click on UIimageview. Press Ctrl and drag downward or sidewise to parent view.
3) click on "centre vertically in view" and centre "horizontally in view"
4) then set height and width like below.
Thats it. your imageview will be at centre regardless of the device type.
good luck.
leave a comment if you any question. Accept the answer if it helps you.
I have an image that needs a UITextField in the middle of it at all times. However, I can't get it do what I want.
I pinned the image with top, left and right constraint and gave it a height constraint. I put the UITextField in the middle of the image and tried various methods to keep it in the middle, but they all keep failing. Any tips are appreciated. Here is what the image currently looks like. First one iPhone 4 and second one is iPhone 6
You can just select the image view and the button and create two constraints: a “Horizontal Centers” constraint and a “Vertical Centers” constraint. Neither view has to be a subview of the other, and they don't have to be in the same superview either.
Here's a demo. I've already constrained the image view to fill the top left quadrant of the root view, and I've dragged in a button. In the demo I'll select the image view and the button (hold shift to select multiple views) and create the two centering constraints. Then I'll use the Preview assistant to show that the button stays centered when the image view's frame changes.
What you need to do:
Embed the UIImageView and UITextField inside a UIView.
Set constraints of UIImageView leading, trailing, top, and bottom to UIView with constant of 0.
Set constraints of UITextField center horizontally with container view, and center vertically with container view.
Then it's up to you on where you want to position that UIView. This will definitely always position the UITextField to the center of UIImageView.
I have a UIViewController that consists of a UIImageView then I want to provide three options to user namely, rotate, crop, draw.
I want these three buttons to remain always centred at the bottom and maintain an exact distance with the UIImageView.
How can achieve this using auto layout I have done a lot of search as well as work but to no good use.
Set constrain like this ,
First set Constrain to centre button(Crop Button). like,
Crop button :- Bottom spacing from bottomlayout , height and width (According to your requirement), and Centre Horizontally in container (now your crop button is fix in centre)
Rotatebutton:- set Horizontal spacing from crop button , rotate buttons top=cropbuttons top , rotate button's bottom=crop buttons bottom , and Rotate button's height and width equal to Crop button's Height and Width.
(set constrain to draw button same as rotate button)
So, all button's look same .
check in image ,
1) Set constrain to Buttons
2) Now set constrain to imageview
3) Output
Edit :- Here i have attached demo ,
Demo for Centre button
(1) First add ImageView, constraints like this
(2) now add an UIButton in the bottom center named CROP. Give Constraints like this
(3) Now add 2 UIButtons named ROTATE and DRAW on either side of CROP
for ROTATE:
for DRAW:
(4) Finally select 3 buttons and give equalWith Constraint
No need to add Constraint to with ImageView. Add these buttons on a UIView and add the constraint on that view as Horizontally Center and also add ImageView on a UIView. Now add the constraintHorizontally Center on the parent view of Button to the parent of ImageView.
Your scenario should be like below,
left most button should have two constraints(cancel) : leading,bottton
right most button should have two constrains (yellow button) : trailing,bottom
Take one UIVIew and put thhree buttons in that view with equal distance from every side of that uiview.
now your constraints to all three buttons should like : leading,trailing,top and fixed height
And constraints of that uiview should be : horizontally center in container, bottom and fixed height
I am attaching screenshot aswell
You can check constraints from view hierarchy on left side.
I have set gray background color to just demonstrate this is view you not need to set color of that view.
By this way your three buttons will always display to bottom center of your VC
hope this will help :)
Hope the below steps might fix the buttons the way you wanted.Have not tried myself but you can try out if you have not tested these steps.
1.Pin those buttons to the bottom space container
2.Add a constraint from button to top space to image view
3.Play around horizontal spaces between buttons by pinning leading edge to the view for the left most button and trailing space to the view from right most button
4.Check center horizontally/vertically to the container
I can't figure out how to make the label horizontally center in a image view, The label says "You've been here. What would you rate us, I want the What would you rate us to be under the "You've been here." What I attempted to do accomplish this was to add 2 lines to the labels and select the label plus the 3 buttons and clicked on "Add Missing Constrains". When I run the program this is the result.
How can I fix it so the text is entered on all devices?
Constrains
for your label try to add constraints like:
Add top, width and height constraints as shown in below screen shot and make sure that constraints to margins is uncheck.
And set horizontal center constraints.
Add Vertical top spacing for the particular imageview
Add center horizontal at in same imageview
Then adjust the leading and trailing as same as drag and drop way. it just easy.
just use this code :
yourLabel.translatesAutoresizingMaskIntoConstraints = YES;
CGPoint centerPoint = yourLabel.center;
centerPoint.x = yourImageView.center.x;
yourLabel.center = centerPoint;
Click the label
Don't set any heights
Now set top space to the container view
Centre horizontal to container view
Now set the height (or) bottom space to the smiley
Add this all constraints you will get what you expected.
How to Align Two UI Button Horizontally Aligned in A Xib Using Size Class and Auto Layout. Two Button should keep its original height and width
i would like to achieve this without code
Thanks in advance
First add gallery button:
Height constaint
Width constraint
Leading space with superview
Top space with superview
Then add camera button:
Horizontal space with Gallery button
Equal width with Gallery button
Equal height with Gallery button
CenterY with Gallery button
And it should be done.
Check this video, to set the constraints
You can check in the preview,
Select both Buttons.
Add the following constraints show in image
This will add default height depend on Text Font.
So if you want to increase height then Select any one button and add extra height constraint. Update the frame.
Just simple select Two Button and Give horizontal and vertical spacing constraints and give Equal Width and Equal Height to Button.
Connect your Gallery button to your main view's corner and set it using
Next, connect your Camera button to Gallery button and set Horizontal Spacing.
Inside your Storyboard's Leading Alignment Contstraint, set Gallery.Trailing as First Item, and Camera.Leading as Second Item. Set Relation to Equal.