Reset Constraints for the other components after removing a UIView - swift

I got a banner UIView which I want to remove if the user has NoAds Feature.
Problem is after I remove the banner UIView, I cant' find a way to set the constraints of the top view to wrap the rest of ViewController.
Here are some images for you to better understand.
I remove the banner UIView with removeFromSuperview() method.
On the storyboard, my bottom constraint is set to 0 towards the nearest neighbour which is the UIView banner at the time. Problem is, after I remove the Banner UIView, I want to set the bottom constraint of the above UIView to 0 towards the SuperView.
Thanks in advance.

Just you can use simple solution
you can set TopView , Banner in Vertical StackView with Distribution Fill
alignment Fill
When one of Stack-view item Hidden then other will Expand
See Image
If you need To use Constrain you have activate and deactivate then call setNeedsLayout()

Related

How can I make ScrollView full screen? I placed the necessary constraints, but it doesn't work

I'm trying to make a ScrollView so that its size adjusts to the size of the text. I placed all the necessary constraints
, but when the application is displayed on the simulator, the content view starts from the safe area and also ends up to the safe area. Although I have pinned scroll view to superview and content view to scroll view.
I want the content to start not from the safe area like here ,
but from the start of the screen like here
in other words, I want to remove the blue bar from the top and bottom
Do you have any ideas how to do it?
Sometimes UITableView & UIScrollView can still show safe area even though you attach your View to top of Super View. You just need to add one line to solve this issue but make sure your ScrollView is connected to superView not safe area at the top.
Add scrollView to your ViewController and in viewDidLoad() just write:
scrollView.ContentInsetAdjustmentBehavior = .never
Check this answer for further details: Make UITableView ignore Safe Area

Keeping an image view out of scrollview scope. Xcode, Swift

Please take a look at an image below
There is a scroll view. But I don't want an imageView(topBar) move. How can I keep an image view out of scrollview scope? (I mean fixed topBar, no move) With a constraint? And managing the constraint from code behind during the scroll?
Move the top bar image so that it isn't in the scrollview. It's parent should be the View0 Outlet, then you can constrain it however you want without it moving in then scrollview.
Using a stackView with vertical setting and free form. In this case, you can lock the height of topBar.

autolayout constraint not working

I want to implement scrollview (Horizontal scroll)with paging and one of the page also contains another scrollview (Vertical scrollview) but elements in scrollview not follow autolayout constraints.Please suggest me way to implement it.
Here also attached image what i want to implement it.
Thanks
Nirav Zalavadia
Embed contents in the scrollview to a UIView. Set constraints to UIView withrespect to scrollview and set constraints to elements with respect to UIView.
While setting the constraints for UIScrollview and its container UIView, check whether the content size is setting correctly. Otherwise there is some problem with the constraints you have added.

Making an Expanding Scrollview

I'm currently making a drawing application in Swift, but I wanted the page to be able to expand if the user wanted more room. I figured that I would use a UIScrollView to scroll around the canvas, but I wanted it to expand whenever the user went to the edge of the page, and for the UIImageView that I am drawing on to expand with it. Does anyone know how I would go about doing this?
Thanks!
In storyboard, drag a UIView into your UIScrollView then constrain that view to all sides of the scroll view. Then set the width to whichever value you would like (I would recommend to control drag from your view to the root view of the view controller and select equal widths), then give it a height constraint. Next, you need to connect an IBOutlet to your view controller code for the height constraint you set on the content view inside the scroll view. When you need to extend the page, add to the value of the height constraint and call layoutIfNeeded() on the scroll view.

label and scroll view

HI FRIENDS..
I use a scroll view and a label now i want that when i scroll that , label also scroll with that and set to next location , i set paging enable = YES , so i want that there are 5 images and when i did scrolling the label i set is also move and show in other position.
thanks
To scroll a UILabel (or anything for that matter) WITH a UIScrollView, simply add the label to the UIScrollView.
You can easily do this in Interface Builder by the obvious methods.
You can also do this programmatically by utilizing the addSubview: method.
You can do one thing you change frame of label when you scroll in delegate method of scrollview or you can also make 5 same label in all 5 pages.
Good Luck
Well if you have added a scrollview on top of a uiview you can add that label on the view and then bring it to front. then you dont have to worry about changing frame of the uilabel as it will be always on top of the scrollview and at the same position and also you can change the text of that label when the user scrolls in pagecontrol value changed method.