UIImageView not showing on top of MKMapView - ios

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...

Related

bringSubview(toFront:) seems not working

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.

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.

UIView overlaps UISegmentedControl

In my app, I want to add a UISegmentControl on top of a UIView.They are siblings of a parent UIView.I pull a UIView to the canvas from object library first, and then pull a UISegmentControl second,but unluckily the first added UIView overlaps the UISegmentControl. What I want is that UISegmentControl is on top of the UIView. I mean UISegmentControl z-index is higher than the UIView.
The following is the screenshot.
One potential solution would be to programmatically send either the UIView to the back or the UISegmentedControl to the front in viewWillAppear(animated:) using parentView.bringSubviewToFront(segmentedControl) or parentView.sendSubviewToBack(otherView). It doesn't solve the issue of the incorrect appearance in your storyboard but it ought to fix the issue once the app is running.
1) First reduce the width and height of the overlapping view to understand its location in view hierarchy. Share your view hierarchy here so we can see in detail.
2) Delete everything from storyboard. Add UIView and then add any subviews. These 2 controls should be children of UIView in view hierarchy.

iOS: Stretching ImageView Above My TableView?

I have added a UIImageView on top of my tableView in storyboard & it works perfectly fine, except that when you scroll down, the imageView doesn't stick to the navigationBar and instead only sticks on to the tableView (revealing the view's background above it).
How would I get it to stick to both the tableView and the navigationBar, and just have the imageView stretch/zoom as the user pulls the tableView down?
This is how it's set up in storyboard:
And this is how I assign an image to it in my ViewDidLoad:
childHeaderView.image = [UIImage imageNamed:headerImage];
Any help would be greatly appreciated. I've tried setting constraints on it using autoLayout but it doesn't seem to let me (they're grayed out, even though I've enabled it for that ViewController).
The problem is that what you did in storyboard is adding the UIImageView as a header to your UITableView.
The proper way to do this is to add the UIImageView at the same level as the UITableView, which mean embed these two views inside a UIView.
Having a UIView as a root view for a view controller is unfortunately impossible for a UITableViewController, and I fear that this is your case. So you may want to replace your UITableViewController subclass by a UIViewController subclass.
EDIT: You'll want to set a fixed height constraint on your UIImageView, and add a vertical space constraint with a 0pt value between your UIImageView and UITableView.
Most of these can be achieved by moving view in IB.

UIView not appearing on xib

I am trying to make a UIView appear as a rounded box on terms and conditions screen as seen here
When I add an UIView to the xib IB the UIView doesn't show up. But if I add a UIButton to the view then I see the view. How can I make the UIView always visible to a specified frame size?
The problem was that I didn't connect the view to the controller.

Resources