任何人都可以幫助我添加多個自定義按鈕到導航欄的右側欄。 如果可能,請用詳細代碼回答,以便我能正確理解。在導航欄中添加多個按鈕
5
A
回答
10
//添加BTN導航欄
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 75.0f, 30.0f)];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setFrame:CGRectMake(0.0f, 0.0f, 30.0f, 30.0f)];
[btn1 setTitle:@"1" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(btn1Tap:) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:btn1];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn2 setFrame:CGRectMake(35.0f, 0.0f, 30.0f, 30.0f)];
[btn2 setTitle:@"2" forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(btn2Tap:) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:btn2];
UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithCustomView:customView];
[self.navigationItem setRightBarButtonItem:rightBtn];
5
請通過這個link。它會解決你的問題。快樂編碼
4
由於iOS 5的右側有可用
- (void)setLeftBarButtonItems:(NSArray *)items animated:(BOOL)animated;
- (void)setRightBarButtonItems:(NSArray *)items animated:(BOOL)animated;
- (void)setLeftBarButtonItems:(NSArray *)items;
- (void)setRightBarButtonItems:(NSArray *)items;
這4種方法,你可以設置UIBarButtonItem
示例:
NSArray * buttons = @[button1,button2];
[self.navigationItem setRightBarButtonItems:buttons];
相關問題
- 1. 添加後退按鈕到導航欄
- 2. 如何添加按鈕到導航欄?
- 3. 添加按鈕自定義導航欄
- 4. xcode添加按鈕導航欄
- 5. 將按鈕添加到導航欄
- 6. 使用智能GWT手機添加多個按鈕,導航欄
- 7. 在導航欄中添加一個「+」按鈕
- 8. 在導航中添加第一個和最後按鈕欄
- 9. 在iOS的頂部導航欄中添加多個然後一個按鈕
- 10. 導航欄上的多個按鈕
- 11. 嚮導航欄添加兩個以上的欄按鈕項目
- 12. 在導航欄上添加兩個以上的按鈕
- 13. 如何在導航欄上添加2個按鈕?
- 14. 在Xcode的導航欄左側添加一個按鈕
- 15. 導航欄按鈕
- 16. iPhone在導航欄中添加項目/行按鈕
- 17. iOS:在自定義導航欄中定位導航欄按鈕
- 18. 將右欄按鈕添加到導航欄的問題
- 19. 將導航按鈕添加到統一標題欄/工具欄
- 20. 如何爲ABPersonViewController的導航欄添加一個返回按鈕?
- 21. 在xcode4.2導航欄中的多個右鍵按鈕
- 22. 添加導航欄
- 23. 無法在導航欄上添加按鈕
- 24. 如何將按鈕添加到IntelliJ中的「導航欄」?
- 25. 導航工具欄中的jqGrid添加按鈕不起作用
- 26. 右鍵欄按鈕不在導航欄中加載
- 27. iphone 2按鈕導航欄
- 28. jQuery和導航欄按鈕
- 29. 更改導航欄按鈕
- 30. 導航欄和按鈕
我想添加兩個按鈕,那些是自定義按鈕。 – SJS 2011-04-20 05:18:24