Aqlier/ 6月 4, 2018/ iPhone

Xcode で、MapKitを使用するとInterfaceBuilder上で容易にボタン設置ができますが、GoogleMapsを使用した際の表示が理解できず、InterfaceBuilder上のボタンがMapの下に隠れてしまい表示がうまくいきませんでした。

Google Maps上に実装でボタン設置する方法をまとめました。

コードは、Objective-cです。


    MapButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    MapButton.frame = CGRectMake(200,80,80,40);//ボタンの位置(x,y)、大きさ(width,height)
    
    [[MapButton layer] setCornerRadius:15.0f];//角丸の割合
    [[MapButton layer] setBackgroundColor:[[UIColor colorWithRed:0.9 green:0.5 blue:0.5 alpha:0.7] CGColor]];//背景色
    [MapButton setTitle:@"戻る" forState:UIControlStateNormal];//ボタンの表題、表示方法
    
    MapButton.titleLabel.font = [UIFont systemFontOfSize:30];//ボタンのフォントサイズ
    MapButton.titleLabel.textColor = [UIColor redColor];//ボタンの表題の色 →NGになる!
    
    [MapButton addTarget:self action:@selector(mod_sec:) forControlEvents:UIControlEventTouchUpInside];//ボタン押された後の処理
    
    [mapView addSubview:MapButton];//ボタン表示