4
我需要導航欄左側的兩個按鈕。我已經想出瞭如何做到這一點的唯一方法是首先將它們放入UIToolbar,然後將leftBarButtonItem設置爲該位置。如果在工具欄中點擊,UIBarButtonItem不會突出顯示?
如果我這樣做,它的工作原理是正常的(你可以看到它突出挖掘時):
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];
任何想法爲什麼這會導致按鈕在觸摸時不突出顯示?