I am new to iOS Programming and I have downloaded the google maps sdk for iOS and followed the instruction on their website ( as shown in this link https://developers.google.com
GMSMapView
is subclass of UIView
so you can add subviews as to any other view
Try this code
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(mapView_.bounds.size.width - 110, mapView_.bounds.size.height - 30, 100, 20);
button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
[button setTitle:@"Button" forState:UIControlStateNormal];
[mapView_ addSubview:button];
It adds 100x20
button as the subview of the GMSMapView
, positioned to the bottom right corner. I have tested it and the button can be touched as in any other view
Edit:
Also move all your code from -loadView
to -viewDidLoad
. -loadView
method is never called when using IB to create UI. Docs to -loadView
says:
If you use Interface Builder to create your views and initialize the view controller, you must not override this method.
Edit 2:
I believe when you create view hierarchy using Interface Builder, you CAN NOT reset self.view
property like you are doing.
Do this in your -viewDidLoad
[self.view addSubview: mapView_];
instead of
self.view = mapView_;
if you are passing GMSMapView
to the self.view
property, the map is only view which is in the controller from this point. Thats, I believe, the reason why u can't see your IB-created button.