so my storyboard look like this
But when I open on iOS simulator, the item (playing card) is off to the right
What is wrong with the spacing/alignments of Storyboard?
(This is with the most recent iOS 8 and XCode 6)
Select the playing card ImageView and press the Align button in the auto layout toolbar.
Check the Horizontal Center in Container, ensuring the value is set to 0, and click Add 1 Constraint.
Then press the Pin button and add a top spacing to nearest neighbour constraint of 0, as so:
Add constraints to make it horizontally centered in the view. It will do.
See Apple's document, it will help.
I was literally bugging out about this same problem with the same example. I finally figured it out.
First constrain the size of the button. Then with descending contraints: Align center x to center x of button. Align center y to center y of button. BINGO!! Thanks for your input. #Adrian Sluyters. I firth thought the Detail View was a zoomable view, but the constraints simply adjust where the center of the view is. Lesson learned.
See my post:
Detail View on Storyboard too zoomed in - creates misaligned objects in simulator
Related
I'm totally new to Swift and in general, to iOS development. I just want to center a rounded profile picture with a table view above. In iPhone 5 it looks centered, but in iPhone 6 and 7 it look aligned to left, I don't know how to fix with constraints, I'm a little bit confuse.
This is my constraint tree:
How it looks storyboard for iPhone5
How it looks storyboard for iPhone 6/7
This is how it looks in emulator with iPhone 6
Can you guys help me to figure out what I'm doing wrong?
Thanks in advance!
Cheers.
It looks like you've set the width and height of your image view to hard-coded values, which will result in it looking centred for some views, but not all.
Reset your constraints, then set your distance from each of the four sides to zero. That'll centre your image!
Go to Editor -> Resolve Auto Layout Issues -> Reset to Suggested Constraints...
...then click that button down the bottom right and set each of your four sides' distances to zero.
Make sure you set Update Frames to "All Frames in Container" before clicking "Add 4 Constraints".
Try setting horizontal constrain between your My UI Image View and HeaderView. You can set centre hozintal with HeaderView.
Go to button down the bottom right and set centre vertical and centre horizontal to your My UI Image View.
Hope it helps. Happy Coding!!
I am new to iOS and am trying to align these TextFields in iOS. Below is how I would like it to look on an iPhone 7.
However, on the iPhone 7 Plus, the TextField shifts to the left of the center, despite my constraints.
Why is this? I have a constraint that aligns them to the Center, as seen on the right part of the screenshot.
It is very simple!! Just follow below steps,
Open you .xib or .storyboard file
Select view you have to add constraint
Click on align button at the right - bottom corner
Set horizontally in container constraint 0
Then press add constraints button
You can add any constraints to any view by following these steps
You just have to seth trailing and leading space fixed means both left
and right indicators should be red as shown in the screenshot.
For more details see the screenshots:
It will remain fixed from left and right in all the screens.
in your case is important set the width constraint.
However you can use trailing and leading constraints, in this way you will not need to set a defined width for your textfield and the position is correct for all type of devices.
If you want design like this so you have to take UITableview then take UITextfield for every cell beacuse you use every cell as view so easily manage all textfield and constraint. And also easily scrolling if device is display small.
I am working on an ios app where I want to have two buttons at a fixed distance from each other. Something like below:
I tried dragging one constraint between the two images. But when I run it in simulator it shows overlap as below.
Can someone guide how to put both the pictures at a fixed distance. Also, I am seeing when I turn the simulator as right in hardware option some of my buttons are not getting auto aligned to horizontal screen and doesn't get displayed. How to fix this too?
Thanks
First of all clear all constraints. and follow below steps :
select both button with command button press
Give Width & Height constraints for both. (Pin at bottom-right side)
give Horizontal Centre in container constraints for both. (Align at bottom-right side)
Now, update all constraints (Resolve Auto-Layout Issue bottom-right side)
Hope, it's work..
Design your view according to this image
Drag a new view and then put your two button in it
Constraint for new view
Top
Horizontal center
Fix height and width
Constraint for left button
Top and leading
Fix height and width
Constraint for right button
Top and traling
Fix height and width
It will work defiantly.
I have read lot of documents and tutorials about autolayout and constraints but I don't know what I'm doing wrong but in my case the examples doesn't work...I know that this is a repeated question but I don't know what I can do...
I'm trying to fix a button to my bottom screen. Bottom with 0 distance. In 4 hinches screen all is ok but when I'm changig to 3,5" the button dissapear. This is what I'm doing:
Normal button
Select button and add the bottom space constraint
Button look likes fine
When screen size changes, the button dissapears
Thanks a lot!
You can complete the following steps to achieve that:
Add bottom constraint, width and height:
Add horizontal centre constraint:
Now you can test on your storyboard by clicking the Apply from factor button:
Select the button, and select "Update Frames"
Suggestion: you should add constraints to the button for left, right and height.
I am using the Interface Builder to create this UI:
And when it is in portrait the One and Two TextViews fill the width of the screen (which is what I want), but when I rotate it to landscape mode the TextViews do not take up the full width of the screen.
How can I get the TextViews to fill the width of the screen in landscape mode? In the Interface Builder, the "Autolayout" option is checked and if possible I would like to accomplish this with it still checked since everything else works best with it on. Any advice would be greatly appreciated since I am still fairly new to iOS programming.
Now the screenshots are posted below. If you notice text box One for example goes all the way to the edge in Portrait view, but not in Landscape view.
If you dont want to use AutoLayout, You can use following steps.
1) In your XIB uncheck autoLayout check box.
2) Select your TextField and set autoResizeConstraints as follows.
Tyr this .... It will help you....
You can either change the textView size programmatically when t change to landscape in the method
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
Select your UITextView and press the "Pin" button.
Click the left and right constraints so they turn from dotted light red to red.
Enter your required distance from the superview. In my example, 5 pixels.
Remember, these two constraints are not enough to define a position of the UITextView.
To do this you must either:
Pin the view to either the top or bottom and provide a height
constraint.
Pin the view to both the top or bottom
Center the view vertically in the container
Align the view with some other subview that has a resolvable Y
position