Autolayout - text field is vertically stretching when run in simulator - ios

When I run my Swift app in an iPhone 6s simulator, the text field seems to be getting vertically stretched. The storyboard can be seen below:
The app running in the simulator can be seen here:
I am not sure how to prevent this. I would like the bottom text field border to be closer to the placeholder text. Manually changing the height of the text field in the storyboard has not worked. I have constraints from each side of the text field to the respective side of the parent view. The storyboards are set to iPhone 6s and the simulator is set to iPhone 6s, surely the storyboard content should look almost identical in the simulator. Can anybody offer any assistance on this?

Remove the bottom constraint of the textfield! It is causing the textfield to increase height when view gets bigger.
To increase the size of the textfield with the size of device, you should add one more constraint: Aspect Ratio.

There must be problem with the constraint. First set your textField contraint to center vertically, center horizontally or remove one of the constraint upper or lower one.

Related

LaunchScreen.storyboard appearing differently on devices than in Xcode?

I am attempting to customize the default LaunchScreen.storyboard of my Flutter app. I simply have a red background on the default View, and I added an Image View as a child of it. This Image View is centered on the screen and renders an image that I have added to "Assets.xcassets" with all 3 sizes. Below is a preview of what my Xcode displays:
However, this storyboard renders differently on devices than it appears in Xcode. For example, it appears slightly off-centered on iPhone 12, and it is scaled up too high for iPhone 6s and is way off-centered. See below for screenshots:
As you can see, the storyboard renders differently on the two devices. How can I make the storyboard appear the same on both devices as it does in Xcode? Any help is appreciated. If I used any incorrect terminology or need to provide additional details, please let me know as I have minimal experience using Xcode.
From the storyboard screenshot attached, it looks like there are no constraints added to the UIImageView.
You should add top, leading, bottom & trailing constraints to superview with 0 spacing to achieve what you want.
UPDATE
Above is applicable to the case when you have a small size image like 100x100 or similar that can easily fit on all screen sizes. In the comments, we see that image is way too big and we want to keep it in center while occupying 50% of screen width.
Remove the leading and trailing constraints, select the imageView and it's superview - add equal widths constraint with a multiplier of 0.5, this will make sure that imageView will always occupy 50% of the superview's width.
Also add horizontally center constraint on the imageView. Make sure imageView Content Mode is set to Aspect Fit.

Constraints with Label on Image View

In my app I have a Image for my background with labels on top of it that are not moving correctly on the iPhone 6 Plus. I am having trouble with the constraints to make the labels move correctly with the image. With the screenshot I attached what constraints should each label have to keep it aligned with the image? Thank you!
screenshot
this shows the suggested constraints
constraints
Your constraints aim on left alignment. So that's way it only works on the size that you were building on, and other display sizes are not aligned properly.
Try to, at least these:
add left leading constraint between superview and textField
add right trailing constraint between button and superview
add spacing constraint between textfield and button
set exact width constraint of your button.
... then add suggested constraint or add your own to them.
Like this (iPhone 6):
View as iPhone 6 Plus:
View as iPad Portrait:
... etc
Is that exactly what you asked?

Swift how to resize elements depending on screen size

I've got all my elements in the view and have added constraints to position them correctly on any device.
But when it's run on a 3.5 inch iPhone some of the bottom stuff is cut off and when it's run on a iPhone 6Plus there's a lot of extra space on the bottom.
How could I resize all the elements to look good on all devices?
This is a universal app to run on iPhone and iPad.
I guess you constraint an element as width equals 300...It's very bad for some elements that should fill (or fill percent of) the screen. I suggest you make percentage constraints. For example, make equal width to view, click Edit button and set Multipiler 0.6. It looks like this in storyboard:
make two constraints (trailing and leading for example) and make aspect ratio for your image, maybe this will help you.

Why my UILabel 's AutoLayout not working

in storyboard I set view controller size iPhone3.5-inch
add constraints with UILabel
UILabel.text cannot show all,so i change view controller size iPhone 4.7-inch
so i tap UIlabel update frame , autolayout work, it all ok!this is iPhone 4.7-inch
now the problem coming,when i run in iPhone simulator iPhone 6, autolayout don't working, the label size only zoom, the width don't change longer。 and The following three images constraints width and height both 32,but in simulator iPhone 6 images size Look bigger,Why is this so? please help me ,very thinks
No matter iphone6 or iphone5 iphon6+ ,code here output 320, why...
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
NSLog(#"%f",self.view.frame.size.width);
}
As per your question if you want text should not display ... then all you need to do is set number of lines = 0 and set Line break mode to word wrap.
As you are working with label it does not require any height constraint.
If you are building your application with size class and using launchScreen.xib then you label won't zoom and if you are using launch image then you need to all splash screen image of exact size.
You can find out about size of splash screen in below url.
https://stackoverflow.com/a/26191308/4101371
I've added images of view with constraint and changes in properties of label.
result will be displayed similarly in device and simulator.
And if you don't want to display label in multiple lines then you can set Auto Shrink (Minimum font Size/ Minimum Font Scale)
Hope it will help you in solving your problem.
Don't you forget to set constraints for your arrow image?
Set trailing and top constraint with fixed height/width.
Set 'Autoshrink' property of your label to 'Fixed font size'
this prevents label from changing font size depend on it's frame
Recreate your constraint for images - it looks like it pins to superview, so in runtime it scales to the size of superview
Hope this helps.

Xcode Auto Constraints not Working Properly

For some reason when I add constraints, by clicking "Add Missing Constraints," it actually looks worse than without constraints in the iPhone 4S simulator.
Here is how it looks in Xcode:
Here is how it looks in the simulator:
Notice that even with the auto constraints, the top text is hidden in the simulator. I want it to look exactly like it looks in Xcode, but I cannot figure it out. I have played around with the constraints for hours now to no avail. It looks better and better with the bigger screen size I use in the simulator, but I need it to have a universal look across all devices. What am I doing wrong?
First remove all constraint for the view.
1) Apply pin Width and Height constraint for your all three controls.
2) Apply Top space from Top Layout Guid for all three controls.
3) Apply Align Centre Horizontally in Superview of your all your three controls.
After applying above constraints your controls will appear in centre in any device.
I believe the three controls should be centre aligned with the top view and the vertical space between the three controls is constant.
The controls will automatically adjust their width according to the text given. So all you have to do is to only add the constraints for their positions. So each control will need two constraints, only for Y position, another for X position.
And of course, you can change the multiplier of the constrains to support the Landscape orientation.

Resources