1

有没有办法获得一个像这样的 3D 按钮:

在此处输入图像描述

我想做的是这样的:

 MK3dBUTTON *3dButton = [[MK3dBUTTON alloc] initWithMapView:self.mapView];
 [3dButton setTarget:self];

UIBarButtonItem *3dbarButton = [[UIBarButtonItem alloc] initWithCustomView:3dButton];
[self.uiTollbar setItems:@[3dbarButton];

那么我怎样才能直接在代码中使用这个 3d 按钮呢?

谢谢

4

1 回答 1

0

我的解决方案:

UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(changeMapViewButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 50, 30)];
[button setTitle:@"3D" forState:UIControlStateNormal];
[button setTitleColor:self.view.tintColor forState:UIControlStateNormal];
[button setTitle:@"3D" forState:UIControlStateHighlighted];
[button setTitleColor:[self.view.tintColor colorWithAlphaComponent:0.15] forState:UIControlStateHighlighted];
[button.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:25]];
UIBarButtonItem *changeMapViewItem = [[UIBarButtonItem alloc] initWithCustomView:button];

这是它的样子:

在此处输入图像描述

我试过了:

UIBarButtonItem *changeMapViewItem = [[UIBarButtonItem alloc] initWithTitle:@"3D" style:UIBarButtonItemStylePlain target:self action:@selector(changeMapViewButtonPressed:)];
[changeMapViewItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"HelveticaNeue-Thin" size:25], NSFontAttributeName,nil] forState:UIControlStateNormal];

但随后文本与 UIToolbar 中的图标不对齐。

HTH 多米尼克

于 2014-01-05T08:48:21.473 回答