Xcode Storyboard: Button image gets stretched with autolayout - ios

I have an issue where my storyboard subviews aren't sizing properly in the simulator. For some reason,
1) the image for the settings button (on the top right, marked with the arrow) is getting stretched
2) the text in my black label is getting cut off
Simulator:
Storyboard:
I'm using autolayout. Perhaps I'm missing a constraint? but it looks like everything is snapped to the blue lines. What's going on??

The problem here is that you have set the width constraint of your image view absolutely. That's fine, but you didn't (as far as I can tell) also set its height constraint, so it adopts the height of the original image, which is much taller.

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.

iOS Storyboard View Controller constraints do not work properly

I have my ViewController in Storyboard. Everything seems fine in Storyboard, but when I build it on emulator, it shows strange white place on the side. When I changed the background of my View to blue color, I realized that white space was caused by my View. What can cause this kind of problem?
My hierarchy of wiews and constraints:
My Storyboard view:
View on emulator:
Make sure your scrollViews and contentViews LeadingSpace and TrailingSpace are 0, It seems you are leaving 20 pts from LeadingSpace and TrailingSpace.
Your constraints should look like this:
Make sure you set MainView/ContentView width equals to scrollView.
What you are messing is, you are setting scrollView width equal to ViewControllers View, remove that constraint and it should work hopefully.
Edit/Update:
I have done demo for test and it is working perfectly fine without any workaround. You can see below screen shot of Storyboard Preview for iPhone 5S and iPhone 6S Plus. ViewControllers view is in Blue color and ContainerView is in Orange color.
Here are the constraint of scrollView:
(While adding constraint make sure you press Alt button)
And the ScrollViews constraint are as below:
ContainerView Contraints:
And the ContainerViews constraint are as below:
One last thing, inside container view all view's should have top to bottom constraint in order to calculate the height required for scrollView. And also do not create conflicting constraints as - Setting imageView's LeadingSpace and TrailingSpace to ContainerView(SuperView) and at the same time setting fix width.

launch screen xib not displaying imageview correctly

I'm using a launch screen xib and I can't get the image within the UIImageView to appear. Currently, I have a UILabel with the imageView placed right below the label and also centered horizontally. I set all the constraints for the imageView but for some reason the label appears but the image doesn't. This is my first time using the whole wAny hAny size classes. Is there something I'm missing?
Based on my recent experience, it appears that as of iOS 8.3, any images in the launch screen XIB have to be in the image assets. I do not know if this is the OP's problem or not, but definitely worth mentioning for other folks coming here with the same issue.
This is happening because of the horizontal space constraints of the imageView, both the leading and trailing space to the superview. Here the launch screen is laid out in the wAny|hAny size class. It could not satisfy the Horizontal space -(196) on a smaller device. So what you can do
Remove the horizontal space constrains(both leading&trailing) of imageView
Add widthconstraint to the imageView or Aspect Ratio could be more appropriate
Other constraints looks fine, top & bottom spacing and centre horizontally in container keep as it is

UIView Doesn't allow swipe down to see rest of the screen

I build a view that has contents which exceed the height of the iphone 6 screen vertically.
To test that out, I've set a specific height for my image (600pts) to guarantee that the whole content wouldn't fit on the screen of an iphone 6 and that you should swipe down to see the rest (the label "BYE").
However, when I run the simulator, I cannot swipe down to see the rest of the screen.
I've used Autolayout constraint and set a margin top/bottom between each components and the superview (I don't have any autolayout constraints issues/warning).
Here's the screenshot of the storyboard of my UIViewController:
Here's when I run the simulator, I cannot see the Label "BYE"(which is normal) but I cannot swipe down to see it.
I am using Xcode 6.1 and Swift.
Any suggestion and explanations?
Thanks a lot!
I have redone your screen and here are the steps. The reason for your issue is not setting proper constraints in autolayout. First you need to choose AnyWidth AnyHeight in Xcode which is in bottom of the storyboard.
Here is the screenshots of View in StoryBoard and its constraints
Constraints
Final Result in Simulator
Setting the constraint properly will work for you. Let me know if you have any issues in doing so. Sorry for the image i used its low quality one and its just for test.
EDIT
In Storyboard if you see the bottom of the screen you will see below image. In center of that image there is wAnyhAny.
you need add constraint to thoes components!
Otherwise, some components will be placed out of the screen!
You can learn how to use Autolayout from here
![enter image description here][1]At right bottom of storyboard in xcode you will see triangel Resolve autolayout isuue select in Reset to suggested constraint.

Image not displayed perfectly on table cell

I use auto layout and building app for iOS 7. I am using a custom UITableViewCell. I want to display an UIImageView inside it with some margin from contentView's borders. So I have taken an UIView which has margin from contentView's borders. UIImageView that I want to display is put into this UIView with all edges touching its superview.
Now, issue is the UIImage (green background) which is set to UIImageView is not displayed perfectly. By perfectly I mean that it is displayed but bottom 1px is not displayed. I have set image in storyboard and it looks perfect there as shown below.
But when I run the app then it looks as shown below. Concentrate on bottom black line which is clearly visible in storyboard but not when I run the app.
Please note that cell height in storyboard is 95pts. Image height is 77pts (non-retina). Also when I scroll cell up and down then I see that during scrolling this bottom line is visible, but that time top lines is not properly visible.
I have noticed such sub-pixelization issues when the simulator is in less than 100% scale size.
Especially on scrolling, when you notice it's sharpness fluctuates, it basically indicates that it's not being rendered properly.
So, test this scenario in the iOS simulator in 100% scale size
command+1
or...
simulator menu > window > scale > 100%.
Alternatively, test this scenario on a device as well since it'll be more "realistic".
If the issue persists then give even numbers in the frame size and/or avoid float values *(but don't quote me on this)
I had the same issue with autolayout and CustomCell with a specific image.
What I did was ticking clip subviews, and the problem was gone. You can tick it in IB by checking imageView and go to Attributes Inspector:
Considering that your autolayout is correct, this question may help.
But anyways give it a try and give me feedback

Resources