如何使用分段控件交换Map类型?

时间:2013-06-18 17:46:46

标签: ios mapkit

我希望有人帮我找到解决方法,如何添加或连接分割maptype(标准,卫星,混合)到我的主视图控制器。

1 个答案:

答案 0 :(得分:2)

试试这个

- (void)viewDidLoad
{
      segControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects: @"One", @"Two", @"Three", nil]];
      [segControl addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged];
      [segControl setFrame:CGRectMake(50,20,200,44)];//set frame which you want
      [self.view addSubview:segControl];
}

- (void)indexDidChangeForSegmentedControl:(UISegmentedControl *)aSegmentedControl {
    switch (aSegmentedControl.selectedSegmentIndex) {
            case 0:
                map.mapType = MKMapTypeStandard;
                break;
            case 1:
                map.mapType = MKMapTypeSatellite;
                break;
            case 2:
                map.mapType = MKMapTypeHybrid;
                break;

            default:
                break;
        }
}