我需要导航栏左侧的两个按钮。我想出如何做到这一点的唯一方法是首先将它们放入 UIToolbar,然后将 leftBarButtonItem 设置为此。
如果我这样做,它会正常工作(点击时您可以看到它突出显示):
UIBarButtonItem* myBtn = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStyleBordered target:self action:@selector(doSomething:)];
self.navigationItem.leftBarButtonItem = myBtn;
但是如果我这样做,按钮操作仍然会发生,但没有突出显示(没有您正在点击按钮的视觉反馈):
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];
UIBarButtonItem* myBtn = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStyleBordered target:self action:@selector(doSomething:)];
UIBarButtonItem* myBtn2 = [[UIBarButtonItem alloc] initWithTitle:@"Button2" style:UIBarButtonItemStyleBordered target:self action:@selector(doSomethingElse:)];
[buttons addObject:myBtn];
[buttons addObject:myBtn2];
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44)];
[toolbar setItems:buttons animated:NO];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
知道为什么这会导致按钮在触摸时不突出显示吗?