bringSubview(toFront:) seems not working - ios

I have the following layout.
What I am trying to achieve is make the yellow subview as circle and bring it to front. I tried self.view.bringSubview(toFront:yellowView) but seems not working as I expected. How can I fix this?
-- edit
Sorry for the lack of details.
So on the root view, I have two subviews, top section and bottom section.
The bottom section is empty for now but the top section contains an imageview with same size as the top section and an circle UIView.
So what I want is to bring the bottom part os the circle UIView to front.

Your problem is that the circle UIView is not a child of the root view, but a child of the top view. In order for the circle to appear in front of the bottom view, reorder your view hierarchy.
Make the circle UIView a child of the root view. Then you will be able to bring it to the front of the other views with the code you have shown. In fact, if you make the circle UIView the last child of the root view, it will appear in front of all of the subviews of the root view.
Desired View Hierarchy:
Root View
- Top View
- UIImageView
- Bottom View
- Circle View
In the Document Outline, drag the Circle View and drop it onto the Root View.

If Your circleView and imageView is subview of containerView
then try this code.
self.containerView.bringSubview(toFront:yellowView)

Set clipBounds property to false for UIImageView:
self.imageView.clipsToBounds = false

You must call bringSubview from its superview.
try this;
self.yellowView.superview?.bringSubview(toFront: self.yellowView)
you can add outlet for yellowView.superview if you want.

Related

StackViews Views and Shadows

I am currently working to build my UI with the use of xcode/storyboard. I have a situation where my shadows are under my next stack view row. I tried to bring the UIView1 to front without any luck. There is no gap between the "rows". I see the shadows when I changed the height of UIView1 so I know I have a shadow.
StackView
---- Row with UIView1 + Shadow
---- Row with UIView2
---- Row etc..
I'm missing something but can't get it to work yet.
No need for a separate root view. Just take the shadow out of the stack view, put it above, then use Autolayout constraints to put it right below your UIView1 where it should be (shadow.top = view1.bottom or so to say).
Autolayout is not reserved to constraints between siblings or children, you can add rules between any view in your view hierarchy.
Stack view are only abstract container for views, Stack view does not get rendered on view, So If you are trying to add shadow on stack view then i suppose -
You have to place a view before stack view For this follow following steps
embed a root view to the stack view on which you are willing to add shadow.
Add shadow on that root view.

How to put a UIView in a UITableView and It will be pinned on the bottom

I am trying to build a UITableView Controller, which will be my app's ABOUT information session.
At the bottom of the view, it will be reserved as circle menu. So I need a UIView with height of 200 there, when I drag a UIView to the controller, it always sit as a table cell.
As you can see, the red area always sit under the last table cell group, how to pin it on the bottom of the View Controller.
Thanks in advance.
You can't add a UIView at the bottom of the UITableViewController. If that is a hard requirement you have to switch to UIViewController. And then you can use UITableView and other UIView's as well.
If you are using a navigation controller with UITableViewController then you can use UIToolBar which sticks at the bottom of view controller but have some limitations too. See this
Get UIView controller and put tableview instead of UITableViewController. From side inspector drop UIView out of tqbleview. And in inspector menu for UIView set auto resizing mask for UIView according.

add buttons to footer in UIView in which footer is fixed

I have a UIView with UIScroll for it. I want to add buttons for footer in which the footer is fixed and the scroll continues… Thanks in Advance.
See the view hierarchy in attached screenshot :
You can bind the button action and scroll as per your requirenment.
Full heirarchy :
You can do this like.
Place your scrollview on view and leave some space from bottom for button. then add button on that space. set contraint to it. its simple.
Take one UIView like containerview.
Add scrollview and button in that view
You need to subview a view on scrolls views super view. Set the constraints to the bottom. Then add button on top of the newly added view.
Keep your scroll view behind your newly added view. SO that it will scroll and not the bottom newly added view.

Is it possible to move UIView outside a controller without being cut?

I have 2 UIViewControllers. One is the content an the other is a Slide menu.
And I want to move the button from Controller 2 outside its superview like this
Is that possible? Because I tried to set clipToBounds = NO for the superview. The only result I get is this:
Any suggestion?
Several options here. The most obvious is clipToBounds = NO on the Controller 2's view, and any further subview which the button is contained in.
If you do not wish to set it to NO, then the view cannot be part of the clipped view hierarchy. You then have to move it to a shared superview, such as the container controller's view, the window, etc.

UIImageView not showing on top of MKMapView

In IB, I have added a UIImageView on top of MKMapView(which spans the whole screen above the bottom tab bar). The UIImageView shall represent the map legend.
I have created an IBOutlet for the UIImageView and have synthesized it in the .m file of my mapViewController. I am setting the image programmatically using the following line of code:
[legend setImage:[UIImage imageNamed:#"maplegend.png"]];
I want this image to be there all the time at the bottom right corner of the MKMapView.
But no image is being displayed when I run my project.
Please guide.
I once had the same problem. I solved it by putting the views next to each other instead of over each other in the view hierarchy.
The view hierarchy would then look like this
containerView (UIView)
mapView (MKMapView)
myBanner (UIImageView)
(containerView.subviews == #[mapView, myBanner] in this case)
myBanner can still overlap mapView, because views with a higher index will be placed above views with a lower index.
This would not work:
containerView (UIView)
myBanner (UIImageView)
mapView (MKMapView)
I'm not 100% sure, but I think there is a problem with the MKMapView: it just doesn't want you to put subviews on top of it.
If you also want your legend to be click-throughable (i.e. not accepting touch-events), you would have to create your own UIView subclass for the containerView and override the -hitTest:withEvent: method...

Resources