有沒有辦法讓工具欄空間中的UIBarButtonItems自己平均分佈?iPhone工具欄按鈕間距
8
A
回答
18
在您的UIBarButtonItems之間拖放一個靈活的空格鍵按鈕項。這在IB中很容易實現,請查看控件的底部。
如果你想這樣做程式設計,此代碼應幫助:
UIBarButtonItem* button1 = [[UIBarButtonItem alloc] initWithTitle:@"Button1" style:UIBarButtonItemStyleBordered target:self action:@selector(button1Action)];
UIBarButtonItem* button2 = [[UIBarButtonItem alloc] initWithTitle:@"Button2" style:UIBarButtonItemStyleBordered target:self action:@selector(button2Action)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[myToolbar setItems:[NSArray arrayWithObjects:button1, flexibleSpace, button2, nil]];
2
是啊。使用UIBarButtonSystemItemFlexibleSpace
使用-initWithBarButtonSystemItem:
方法創建UIBarButtonItem
,然後在每個實際工具欄項目之間插入該方法。例如:
UIBarButtonItem *flexSpace = [[UIBarButton alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace];
myToolbar.items = [NSArray arrayWithObjects:buttonOne,flexSpace,buttonTwo,flexSpace,buttonThree,nil];
[flexSpace release];
4
忽略UIBarButtonItem建議的寬度;這不是蘋果推薦的正確方法,如果你想添加更多的圖標,它將不起作用。
正確的做法是在每個按鈕之間添加一個「靈活空間」(技術上說是另一個按鈕!)。您可以在Interface Builder中看到它,或者如果需要,可以直接在代碼中添加它。
+0
技術上另一個按鈕!從中得到重點 – Anish 2012-08-31 09:56:50
相關問題
- 1. iPhone中的工具欄按鈕之間的間距
- 2. iPhone攝像頭的工具欄按鈕
- 3. wxFormBuilder工具欄間距
- 4. Excel的工具欄按鈕
- 5. 按鈕倒是工具欄
- 6. 工具欄按鈕樣式
- 7. Swing工具欄按鈕
- 8. UINavigationController工具欄按鈕
- 9. 工具欄菜單項間距問題
- 10. 如何使工具欄按鈕比工具欄更大?
- 11. 添加工具欄項目或按鈕DetailViewController工具欄的iPad
- 12. 刪除工具欄按鈕之間的空間
- 13. iPhone - 用於工具欄按鈕的字體
- 14. 按下工具欄按鈕時重新加載tableview的工具欄
- 15. 在iPad上的標籤欄按鈕和工具欄按鈕不工作
- 16. 從工具欄按鈕呈現UIAlertController
- 17. 工具欄(後退按鈕不顯示)
- 18. 鉻擴展:創建按鈕工具欄
- 19. 將按鈕添加到Finder工具欄?
- 20. CKEditor - 按鈕切換顯示工具欄
- 21. iOS:後退工具欄按鈕項目
- 22. ExtJS按鈕樣式工具欄
- 23. Firefox工具欄按鈕應該多大?
- 24. Firefox自定義工具欄按鈕
- 25. nicEdit工具欄按鈕部分可見
- 26. 設置工具欄上的按鈕
- 27. 工具欄與我的按鈕重疊
- 28. 工具欄主頁按鈕方向
- 29. Swift將按鈕移回工具欄?
- 30. 通過點擊按鈕在工具欄
Alku,你已經改變了你的答案三次,以添加所有其他人都在說的話!不是很酷 – h4xxr 2010-05-10 23:27:31
是的,我注意到了,我很抱歉。我第一次誤解了這個問題,然後去編輯我的答案,然後意識到我可以在第三次提供更好的答案,因爲我有一些可用的代碼。當我完成所有這些工作的時候,你們進來了,回答得比我最初的答案還要好。 – 2010-05-10 23:31:23
謝謝你,這是一個很好的答案,我很欣賞你已經努力將答案編譯成一個區域的努力。你是一個好人。 – 2010-05-11 13:36:14