UIStackView inside UITableViewCell: constraints not enabled - swift

I have a horizontal UIStackView inside a UITableViewCell. Why can't I add constraints related to cell's content view in Storyboard?

If stackview ' layout is selected Translates Mask Into Constraints on Size Inspector' View page
You can't add constraints.
Change it with Automatic

Related

How can I add a fixed view under dynamic uitextview?

I have a UITextView Object. I want to add another view under but the TextView fills the whole screen. Couldn't find how to do. What I want to do is show a fixed view when the scroll is finished. How can I do it?
Don't use the textViews own scrollView for scrolling.
Instead setup an outer scrollView that contains the textView and your footerView (either by embedding in a stackView or by setting up your own constraints).
Getting text and scrollView resizing right can be tricky.
Please refer to this guide for details.
To summarize:
Add UIScrollView inside the main view in Storyboard
Add UIView inside the UIScrollView
Add UITextView inside the UIView (the view added in step 2)
Make sure "Scrolling Enabled" of UITextView is unchecked
Add 4 constraints (leading, trailing, top, bottom) on UIScrollView
Add 4 constraints (leading, trailing, top, bottom) on UIView (the view added in step 2)
Add "Width Equally" constraint on UIView (the view added in step 2) and the main view
Add 5 constraints (leading, trailing, top, bottom, height) on UITextView. After this step you shouldn't get any errors and warnings on constraints.
Add UITextView height constraint IBOutlet on the ViewController. #property (nonatomic, weak) IBOutlet NSLayoutConstraint *textViewHeightConstraint; and connect it in Storyboard
Change the UITextView height constraint programmatically. self.textViewHeightConstraint.constant = [self.textView sizeThatFits:CGSizeMake(self.textView.frame.size.width, CGFLOAT_MAX)].height;

Content of NSScrollView sticks at bottom when resizing

When I add a custom NSView to my NSScrollView via documentView and resize the window the content sticks always to the bottom of the window (so the scroll view is always scrollt to the bottom when the window is resized).
Is there a way to keep the scroll view scrolled to the top when the window is resized?
Edit: Uploaded reproducible example:
https://github.com/nathasmike/sample1
The autoresizing mask of the custom view is translated into constraints. To prevent this do
myCustomView.translatesAutoresizingMaskIntoConstraints = false
myScrollView.documentView = myCustomView
Add constraints to the custom view and its subviews.
Another solution is removing the autoresizing mask from the custom view in the xib.

How to add custom UIView to Stackview on top of UIScrollView programmatically?

I have a ViewController that has a UIScrollView with a vertical UIStackView on top of it.
Everything works fine if i add UIView to the stackview with height constraint trough the interface builder. For example 3 views with height 600px. If i run the app, i can scroll with no problem and see all three added views. The for the stackview works fine.
If i try to add a view to the stackview with code with addArrangedSubView trough code i can see that the first view that i added if i "force" scroll down, but not the other two. It doesnt matter if i set height constraints to the views that i add, and it doesnt matter if i set intrinsicContentSize for the custom views.
How can i get the scroll view to expand the scroll area when adding trough code. ?
Thanks :)
Just a guess in lack of more information:
The issue may be related to the way constraints are set up between the scroll view and its child, the stack view.
you should add the following constraints:
fix stack view edges (top, leading, trailing, bottom) to scroll view
set width constraint between stack view and scroll view
also set height constraint between stack view and scroll view, set its priority to low (250)
For more insights please read up on "setup UIStackView with auto layout", for example here:
https://medium.com/#pradeep_chauhan/how-to-configure-a-uiscrollview-with-auto-layout-in-interface-builder-218dcb4022d7
If it doesn't work please provide the relevant code and screenshots of your Interface Builder setup.

My horizontal scrollview is not working

I've added a scrollview to a view in my app, the view is selected from a tab controller and as such is a container and not a UIViewController it is declared as below
class HomeViewController: Container, UIScrollViewDelegate {..
I've added the scrollview in the storyboard and added all of the components to it and I've assigned the delegate from the storyboard and I've placed this code in my ViewController
scrollview.contentSize = CGSize(width:1048, height:scrollview.frame.height)
scrollview.delegate = self
This how my ScrollView looks in my storyboard, you can see that scrollview is my UIScrollView, then I've added a UIView viewScroll and then added four views to viewScroll (View1, View2, View3 and View4), scrollview is sized at 375x340 and viewScroll is set at 1048x340
When I run the app it does not scroll. As it is not a UIViewController, do I need to approach this differently or is there something else I have missed?
I've added the scrollview in the storyboard and set the width as 1050 and height as 330
You should set the width and height of scroll view to be at most as large as its containing view. What you need to set to 1050 and 330 is contentSize of the scroll view - scrollView is only scrollable when its contentSize is larger than its bounds.
If you're setting up your scroll view using Interface Builder, then you'll need to add constraints to its children's edges. For example, in your case you'll have to add leading, trailing, top, and bottom constraints to your View Scroll view. Select it and add following constraints in interface builder:
After that there will be something like this:
When you add edge constraints to UIScrollViews child views, you are hinting the scroll view about its content size. And if scroll view knows its content size and it is larger than scroll view's bounds, you'll have scroll working.

Resize UITableViewCell (created from xib) height according to subview height

I'm able to resize superiew height depending on subview height by setting up the follwing constraints as shown:
]
I want to achieve the same effect in UITableViewCell i created from xib. But i it not happening. I have setup the same constraints shown in the pictures for my UITableViewCell. Is there some thing special i need to do to resize UITableViewCell resize itself according to subview height?
Design ui in TableViewCell in xib and not in view. For dynamic cell height according to subview add leading trailing top bottom constraint. dont add height constraint.
In view controller containing tableview instance put code
mytableView.rowHeight = UITableViewAutomaticDimension
mytableView.estimatedRowHeight = 200.0
You have to set rowHeight like this:
tableView.estimatedRowHeight = 250w