2015-04-04 110 views
-1
NSArray *ary=[[NSArray alloc]initWithObjects:bar_back_1,bar_btn,bar_btn1,nil]; 


// UIImage *img_whiteleftbtn=[UIImage imageNamed:@"img_arrow_white"]; 
// UIBarButtonItem *bar_leftbtn=[[UIBarButtonItem alloc]initWithImage:[img_whiteleftbtn imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:nil]; 
    // self.navigationItem.leftBarButtonItem=bar_leftbtn; 
    self.navigationItem.rightBarButtonItems=ary; 

在iphone4中,我們要在右側設置三個導航項.....如何可能?如何減少導航欄項目之間的空間?

I'm experiencing excessive UIBarButtonItem padding/spacing when using the LeftBarItems and RightBarItems (see image below). The icons used on the UIBarButtonItems do not contain extra padding. So I would like to know what's causing this? 
+0

的可能的複製[如何調整rightBarButtonItems 2的UIBarButtonItem之間的空間(http://stackoverflow.com/questions/22741824 /如何調整空間之間的兩個按鈕右上角按鈕項) – ToolmakerSteve 2017-03-18 01:19:22

+0

http://stackoverflow.com/questions/22741824/how-to-adjust-space-between-two- uibarbuttonitem-in-rightbarbuttonitems,已接受答案,2015年7月更新。 – ToolmakerSteve 2017-03-18 01:19:52

回答

-1

它可能讓你感到困惑。

// Create "Normal" buttons items: 
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"1" style:UIBarButtonItemStylePlain target:Nil action:nil]; 
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithTitle:@"2" style:UIBarButtonItemStylePlain target:Nil action:nil];  
UIBarButtonItem *button3 = [[UIBarButtonItem alloc] initWithTitle:@"3" style:UIBarButtonItemStylePlain target:Nil action:nil]; 

// Create "Spacer" bar button items 
UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; 
fixedItem.width = 20.0f; // or whatever you want 
UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 

self.navigationItem.leftBarButtonItems = @[button1, fixedItem, button2, flexibleItem, button3]; 

此外,如果你有一個工具欄,你可以使用工具欄的項目屬性:

self.toolbar.items = @[button1, fixedItem, button2, flexibleItem, button3]; 
+0

這不起作用。固定空間項目在導航欄中不起作用。 – vahotm 2016-01-05 14:15:36

相關問題