Xcode 10 View Controller Scene Positioning Problem - xcode

I have inserted a label into my View Controller and centred it to the middle. When I run the app on the simulator for iPhone 6 the label is not centred.
I have tried adding constraints to the label. When running the app in the iPhone 6 simulator hides the label completely. What am i doing wrong?

Make the background color of the label to a darker shade.
If there are any red constraints, try to eliminate them
The best method to centre a label is to select the label from the structure hierarchy, click on to the Align button in the bottom, select Horizontally and Vertically in Container to be at 0 value

Related

Unwanted grey area when simulating iPad Xcode 11/SwiftUI

Question: Can someone identify why I am getting the extra grey area shown in my add item (top screen in screenshot) and how to eliminate it?
I have tried manually setting the size of the background object, removing and re adding constraints, clicking all the Xcode generated solutions for handling the autolayout errors shown below, setting the presentation setting to full size ala this answer all to no avail; it refuses to be consistent with the main menu screen (bottom)
Context:
Running Xcode 11...I have two scenes in a generic barcoding app, the main menu and the add item scene, and I am designing with iPad's in mind. With the size class for ipad pro 9 (wR hR) and set to landscape orientation, my add item scene has a huge amount of gray area bordering the visible content, unlike the main scene (though there is also a little grey area in portrait)
Figured out what was causing my problem; was using the wrong form of segue between screens, per this answer, in my case, a modal segue when I should have just been doing a show segue. Deleting and adding show segues with the presentation set to Full Screen in the destination views Attributes inspector did the trick.

How to fix scrollable content size ambiguity in xcode 11 using auto layout beta 7 UIKIT

When using Auto Layout, I am unable to set up a simple UIScrollView in my view controller in Xcode 11 beta 7. I know that I must constrain the scroll view to the edges, and then set the scroll view width and height equal to the width and height of the entire view that contains the scroll view. However, I am not getting the option to set equal widths and heights when I attempt to do so.
When I do the right-click-drag from the scroll view to the entire main view, I get the following options:
Leading Space to Safe Area
Top Space to Safe Area
Trailing Space to Safe Area
Bottom Space to Safe Area
Center Horizontally in Safe Area
Center Vertically in Safe Area
In other videos, there is an "Equal Widths" and "Equal Heights" option that I don't seem to have.
Am I doing something wrong, or did Apple change the way scroll views work in Xcode 11?
I'm using beta 7 currently
I was finally able to successfully add a UIScrollView using storyboards in Xcode Version 11.0 (11A420a) after much trial and error.
You can add the scroll view directly to the root UIView of the VC or, if you needed to, add it to another UIView under the root view as needed by your UI Design. Constrain the UIScrollView parents normally for whatever your needs are.
Here is the key : when you add the UIScrollView to the storyboard, click on the Size Inspector with the UIScrollView selected. You have to UNCHECK the box that says "Content Layout Guides".
If you do this you can set the scroll view's contraints normally (I did 0-0-0-0 to superview). Then I added a UIView to the scrollview and set it's constraints to 0-0-0-0 and a height of 900 (which is what I wanted).
This will give you constraint errors in red when you set them. They will be fixed by setting the width of the UIView equal to the width of the UIScrollView.
Set the UIView width equal to the width of the UIScrollView view by Ctrl-right clicking on the UIView, dragging to the UIScrollView, and selecting the "Equal Widths" option. This should get rid of your constraint errors.
You actually can then go back to the UISCrollView Size Inspector and check the "Content Layout Guides" checkbox, no constraint errors will appear.
Disable the content layout guides in scrollview properties.
Hope it helps.. :)

Overflow-Y scroll not working

I got the constraints just how I want it in iPhone 5 it fits in one screen and in iPhone 4 it overflows to the bottom which is fine. But why can't I scroll down?
iPhone 5:
iPhone 4:
As you can see in iPhone 4 the bottom is not visible and all I want is to be able to scroll there.
Even without seeing how you are settings the constraints on the Interface Builder, I think that doing like below could help you to solve your problems:
Possibly you are not embeding all views in a scrollView properly. If so, select all subviews, choose Editor from menu -> Embed In -> View to wrap everything in a container. (UIView). After that select the container then choose Editor -> Embed in -> Scroll view
Set up all necessary constraints between subviews and the container ( As you did before making the view in the shared screenshot)
Set up all margins between the container and the containing scrollView to be zero ( top/ left/ right/ bottom = 0). Ensure that the scrollView fit the screen by having zero margin constraints as well.
Last but not least, set a width constraint of the container to any number you want (e.g.: 320 /375), then make an IBOutlet for this constraint
On viewDidLoad, set the constant of the container's width constraint you made in step 4 to current screen width.
That's all.

Text starting at wrong position in textview in Xcode 6

There's no code involved at the moment, only storyboard or xib files as far as the textview is concerned. This is what I get when running the app on my iPhone 5s or via the simulator.
I'm using auto layout and size classes with the option any width-any height. An imageview at the top, then a label, then the textview.
Here's a picture of the screen. As you can see, it looks as if the text is starting behind the label, but the textview's y is after the label and the constraints seem all correct according to Xcode 6. It works fine on iPad.
Any idea of what I'm doing wrong?
I've found a way round it: textview should have no scrolling enabled and should be put in a scrollview instead, which will do the actual scrolling. Need to add constraints to both.

xcode button appearing under tabbar

I am using auto layout for everything and I have some buttons that have been snapped into place above the tabbar and in a corner.
The inspector shows no constraints on this button placement. Simulating on a 4 inch screen works fine, but when I simulate on a 3.5 inch screen the button is underneath the tabbar. Why is this happening? The button has "snapped" into place in the corner there so shouldn't auto layout take care of the rest? Or do I need to do something else?
If you have no constraints on an item, then it's placed to a concrete X/Y measured from the top left corner.
If it's in the right location on the 4" screen, then it's at a Y much lower than will look correct on a 3.5" screen. When on a 3.5" screen, the X/Y coordinates will still be measured from the top left corner, 400pixels is much closer to the bottom of a 3.5" screen than it is a 4" screen. If it's 3.5" from the top of the screen on the 4" screen, it won't even be on the screen on the 3.5" screen, etc.
Set your constraints, or adjust the button's location in viewDidLoad based on [[UIScreen mainScreen] bounds].
I recommend the official documentation on autolayout and setting constraints.

Resources