有沒有辦法讓工具欄空間中的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. 工具欄按鈕樣式
- 3. Swing工具欄按鈕
- 4. Excel的工具欄按鈕
- 5. UINavigationController工具欄按鈕
- 6. 工具欄菜單項間距問題
- 7. 添加工具欄項目或按鈕DetailViewController工具欄的iPad
- 8. 刪除工具欄按鈕之間的空間
- 9. iPhone - 用於工具欄按鈕的字體
- 10. 按下工具欄按鈕時重新加載tableview的工具欄
- 11. 在iPad上的標籤欄按鈕和工具欄按鈕不工作
- 12. ExtJS的工具欄按鈕的HIGHlite
- 13. 劍道UI工具欄按鈕
- 14. 更改工具欄按鈕backcolor
- 15. CKEditor - 按鈕切換顯示工具欄
- 16. 如何禁用TTNavigator工具欄按鈕?
- 17. 刪除TinyMCE工具欄按鈕
- 18. 禁用Infragistics工具欄按鈕(ButtonTool)
- 19. 添加工具欄按鈕插件
- 20. 更新工具欄按鈕狀態MFC
- 21. PyQT中心工具欄按鈕
- 22. 工具欄(後退按鈕不顯示)
- 23. 從工具欄按鈕呈現UIAlertController
- 24. 每個場景的工具欄按鈕
- 25. Froala的所有工具欄按鈕
- 26. iOS:後退工具欄按鈕項目
- 27. 工具欄後退按鈕問題
- 28. 將按鈕添加到工具欄
- 29. 刪除黑影從工具欄按鈕
- 30. ExtJS按鈕樣式工具欄
Alku,你已經改變了你的答案三次,以添加所有其他人都在說的話!不是很酷 – h4xxr 2010-05-10 23:27:31
是的,我注意到了,我很抱歉。我第一次誤解了這個問題,然後去編輯我的答案,然後意識到我可以在第三次提供更好的答案,因爲我有一些可用的代碼。當我完成所有這些工作的時候,你們進來了,回答得比我最初的答案還要好。 – 2010-05-10 23:31:23
謝謝你,這是一個很好的答案,我很欣賞你已經努力將答案編譯成一個區域的努力。你是一個好人。 – 2010-05-11 13:36:14