2015-04-04 116 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

相关问题