2014-11-05 61 views

回答

0

爲了做到這一點,您可以從GMSMapView中檢索到該按鈕的UIButton引用。之後,您只需使用標準的[UIButton setImage:]處理所有不同的狀態。我創建了一個類從GMSMapView中控制得到這個的UIButton:

https://github.com/trant/GMSMapView-Additions

2

1)知道幀位置按鈕:

for (UIView *object in self.mapView.subviews) { 
    if([[[object class] description] isEqualToString:@"GMSUISettingsView"]) 
    { 
     for(UIView *view in object.subviews) { 
      if([view.accessibilityIdentifier isEqual:@"my_location"]) { 

       frame = view.frame; 

      } 
     } 

    } 
    } 

使用調試,看看正確的幀!

2)不要使用self.mapView.settings.myLocationButton = YES;

3)到該幀創建自己的按鈕:

UIButton *buttonLocation = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
buttonLocation.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 66, [UIScreen mainScreen].bounds.size.height - frame.size.height, frame.size.width, frame.size.height); 
[buttonLocation addTarget:self 
      action:@selector(bLocations:) 
forControlEvents:UIControlEventTouchUpInside]; 
[buttonLocation setImage:[[UIImage imageNamed:@"image.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal]; 

[self.mapView addSubview:buttonLocation];