Position in relative to parent view with auto layout in Objective C - iphone

I have a UITextView that I want always to be 10px from the bottom of it's parent view (the scrollview). Problem is that I don't know how to tell the auto layout that it is supposed to do Bottom Space To: Parentview, instead of superview.
This is what I have now:
Update:
I need something similar to this:
I got that from here - http://www.techotopia.com/index.php/Working_with_iOS_6_Auto_Layout_Constraints_in_Interface_Builder - I want to have a UITextView in relation to the view it is in.

Click the gear for the “Bottom space to: superview” constraint and edit it. Set the constant to 10.
UPDATE
I've investigated this a bit and decided there's a bug in autolayout. Specifically, autolayout acts as if the size of the scroll view is 0⨉0 instead of its actual size.
Because of tis, if your text view has top-space-to-superview constraint and a bottom-space-to-superview constraint, only the top constraint will be honored. (I tried setting the priority of the top constraint to 1, the minimum, and the bottom constraint was still ignored.) If you delete the top constraint in viewDidLoad, the bottom constraint will be honored, but the text view will be laid out as if the scroll view's height is zero. This means that the text view's bottom edge will be 10 points above the top edge of the scroll view.
This happens in my testing with both a storyboard and a xib.

Related

Make UITableView ignore Safe Area

I have a TableView inside a ViewController.
I made the TableView stretch to the View SuperMargings (with constraints) and disabled all SafeArea Inset options but my TableView is still under the SafeArea when I run my project.
How can I make my TableView go full height on iPhones with notch?
If you have already pinned tableView to it's superview(not to safeArea) with constraints but tableView still respects safeArea there is property contentInsetAdjustmentBehavior in UIScrollView(UITableView is subclass of UIScrollView as we know) since iOS 11.
This property is UIScrollView.ContentInsetAdjustmentBehavior enum with 4 options.
You need to set .never to contentInsetAdjustmentBehavior.
What works with any view is to associate the bottom constraint of the table view to the bottom anchor of the root (or parent) view (instead of the SafeArea).
This can be done in the storyboard editor double clicking on the constraint in the right inspector and changing the first item anchor from SafeArea to Superview (or any wanted view).
You can then set the edge insets at will if needed (to avoid content remain partially hidden behind the rounded frame corners or the notch if applying the same procedure to the top anchor)

How to make this scroll view scrollable?

I'm trying to add a horizontal scroll view to my view controller, but when I run the app I can't scroll. Here's an image:
How should I solve it?
The important thing here is how the constraints of the scroll view and its inner views are set.
You should first set constraint of the scroll view as you would do with another view, once this is done correctly it should have an x and y positions and also would be capable of know width and height.
After that you should set the constraints for inner views, making them push the boundaries of the container (the scroll view). So imagine you have 3 inner views you want to be set vertically:
The first one should have a top constraint to its container (scroll view), and a bottom to the second inner view.
The second one should have a bottom constraint to the third one.
The third one should have a bottom constraint to its container (scroll view).
This should satisfy all the calculation needs by AutoLayout.

Swift: UIScrollView doesn't scroll after the user edits the height of a UITextView

I have two UITextView inside a UIScrollView and the TextView can resize as the user types more text into them. I need the page to be scrollable to account for this so I put them in a ScrollView, however the height of the ContentView doesn't change with the TextViews. Here's what I tried so far:
adding a bottom constraint from the last helper text to the bottom of
the content view with priority 1000 and constant 210. This doesn't
work because the section will be scrollable before the TextViews get
taller and on tablets or larger devices it will make my first
TextView taller.
adding a bottom constraint with a constant of 210 or lower will give me a layout error.
I also thought about calculating the height of the content view and maybe adjusting the constraint based on that but this doesn't work either.
Here is a link to the file in question: https://www.dropbox.com/s/g7q1lbj0pxx14jh/Main.storyboard?dl=0
Any suggestions?
It's also worth noting that the keyboard will cover the second TextView when the first one gets too big so I will eventually need to edit that constraint based on the height of the first TextView (to give it more padding at the bottom so that the user can bring the second TextView in view.
Here is the fixed variant https://www.dropbox.com/s/gujry7ngziaipm7/Main.storyboard?dl=0
I found just 1 error:
You forgot to specify bottom offset from last view in View Container which is UILabel - "Being clear...", so your view container doesn't know when to resize as soon as you do not specified all offsets to it.

fill rest of view in storyboard

How do i achieve the following layout within a storyboard? I have seen related answers in SO suggesting a code solution. But can it be done codeless?
For your toolbar at the top set the left, right, and top spacing constraints with a constant of 0, then set a height constraint with a constant of whatever your fixed height is.
For the bottom container view, set the left, right, and bottom spacing constraints with a constant of 0, and set a vertical spacing constraint to the toolbar, also with a constant of 0.
This will anchor the toolbar to the top and automatically fill the rest of your view controller with the container view.

UIScrollView Causing "Misplaced Views" AutoLayout issues

I'm running into a strange AutoLayout related issue when I use a UIScrollView (the issue does not occur without it).
I have a UIScrollView that is constrained to the boundaries of a UIView (contained within a UIViewController), and within that, I am attempting to place a UILabel and UITextField side by side. I have constrained the UILabel to the left and upper boundaries, with it's width and height constrained (see screenshot below):
Right next to this UILabel is a UITextField, which is constrained to the left, top, and right, as well as having the height constrained. However, this results in a "Misplaced Views" warning, that states "Expected width = 163, Actual width = 413", shown in the screenshot below:
When I choose to "Reset to Suggested Constraints", the "Misplaced Views" issue disappears, but in it's place I am left with a width constraint of 413 points, which is something I'm hoping to avoid, as I would not like this UIViewController to be horizontally scrollable on smaller devices.
A scroll view has a size (the size it takes up on the screen) and a content size (the size of the entire scrollable area). In Auto Layout, the content size is automatically computed from the constraints of the items in the scroll view. This is a problem, because you are trying to make the scroll view have the same width as your screen, and then have the items constrained to that. When you do that, Auto Layout insists that you give your text field an explicit width so that it can calculate the width of your scrollable area.
To do what you want, do the following:
Add a "content view" to your scroll view. This view will be the only top level item in your scroll view. It will hold all of your content as subviews of it. Drag out a UIView and add it to your scroll view. Constrain its top, leading, bottom, and trailing edges to the scroll view. Constrain its width to the width of the scroll view. Give it a height constraint and set it however big you want your content area to be.
Add all of your labels and textfields to this content view. Now you can constrain them centered in your content view or constrained to the edges, and it will work as you want.