I must add an ImageView as subview of MapView. I can not do it by code, because the ImageView always ends up behind the mapView. I can not do it in IB because in the file's owner the UIImageView is always external respect to the mapView ( I tried several times).I am using Xcode 4.5. Can I add a UIImageView as subview of MapView?
this is the code in MapViewController.h
@property (nonatomic, strong) UIImageView *iphoneLegenda;
@property (nonatomic, strong)IBOutlet MKMapView *mapView;
in MapViewController.m
@synthesize iphoneLegenda;
@synthesize mapView;
- (void)viewDidLoad
{
//.....
self.iphoneLegenda.frame = CGRectMake(self.mapView.bounds.origin.x,
self.mapView.bounds.origin.y, 200, 100);
//......
[self.mapView addSubview:self.iphoneLegenda];
[self.iphoneLegenda bringSubviewToFront:self.mapView];
//.....
}
I think the answers of AntonPalich and MashDup are the best way. To add a subview inside mapView you have to add QuartzCore.framework and this is the code:
- (void)viewDidLoad
{
CALayer *layer = [CALayer layer];
layer.backgroundColor = [[UIColor whiteColor] CGColor];
layer.bounds = CGRectMake(mapView.frame.origin.x, mapView.frame.origin.y, 200, 100);
[[mapView layer] addSublayer:layer];
}