我想在工具欄的頂部和中心顯示按鈕。我設置了UIBarButtonItem的圖像,但沒有給出如下圖所示的所需結果。如何在工具欄中心顯示按鈕?
我能夠添加菜單,找到我
但如圖PIC不能添加請求按鈕。
請求按鈕是一個圖像,當我把它的形象的UIBarButtonItem它被拉伸
請幫助
這是我做了什麼。
但我想這樣做。因爲您可以看到,在我的解決方案中,「請求」按鈕位於工具欄下方,下方的「請求」按鈕位於頂部。
我想在工具欄的頂部和中心顯示按鈕。我設置了UIBarButtonItem的圖像,但沒有給出如下圖所示的所需結果。如何在工具欄中心顯示按鈕?
我能夠添加菜單,找到我
但如圖PIC不能添加請求按鈕。
請求按鈕是一個圖像,當我把它的形象的UIBarButtonItem它被拉伸
請幫助
這是我做了什麼。
但我想這樣做。因爲您可以看到,在我的解決方案中,「請求」按鈕位於工具欄下方,下方的「請求」按鈕位於頂部。
只是FlexibleSpace
添加UIBarButtonItem
像波紋管這兩個按鈕的兩側..
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
見有兩個按鈕的所有代碼..
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *locateMe = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(locateMe:)];
UIBarButtonItem *request = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(request:)];
UIBarButtonItem *menu = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(menu:)];
NSArray *toolbarItems = [NSArray arrayWithObjects:locateMe,flexibleSpace,request , flexibleSpace, menu];
[toolBar setItems:toolbarItems animated:NO];
從XIB
您還可以設置UIBarButtonSystemItemFlexibleSpace
如下圖所示..
UPDATE:你想補充一點,請求按鈕與UIToolBar該圖像,然後只是把那個UIImageView
和按鈕後,添加UIToolBar
在UIView
像波紋管..
[self.view bringSubviewToFront:imgView];
[self.view bringSubviewToFront:btnRequest];
從筆尖使用靈活UIToolbar
對象上的空間項目。像波紋管圖片: -
添加中心按鈕更大然後工具欄海特然後檢查該波紋管演示,並使用其類別完成這個任務,只需將您的圖像到演示和改變形象的名字CenterButtonIconPaw.png檢查: -
https://github.com/el-eleven/EEToolbarCenterButton
使用你的形象我這樣做,只要你想它的外觀像類似於您需要: -
謝謝,這是我所需要的。 – Geoff
需要代碼.... – IronManGill
這裏你要在中心顯示這兩個按鈕,爲此只需添加'UIBarButtonItem'類型爲'UIBarButtonSystemItemFlexibleSpace',以便用按鈕調整兩側並將這些按鈕設置爲中心就可以看到我的答案.. :) –