有没有办法得到这样一个3D按钮:
我想做什么,是这样的:
MK3dBUTTON *3dButton = [[MK3dBUTTON alloc] initWithMapView:self.mapView];
[3dButton setTarget:self];
UIBarButtonItem *3dbarButton = [[UIBarButtonItem alloc] initWithCustomView:3dButton];
[self.uiTollbar setItems:@[3dbarButton];
那么如何直接在代码中使用这个3D按钮呢?
感谢
答案 0 :(得分: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 多米尼克