向UINavigationController添加多个按钮

时间:2012-01-16 14:16:46

标签: ios uinavigationcontroller

我有以下代码,为导航控制器添加了一些按钮。我需要这个,这样我就可以拥有一个包含多个项目的工具栏。

CGRect frame = self.navigationController.navigationBar.frame;
frame.size.height += 0.01f;

UIToolbar *tb= [[UIToolbar alloc] initWithFrame:frame];
NSMutableArray *tbitems = [NSMutableArray array];

tb.autoresizingMask= UIViewAutoresizingFlexibleWidth;

UIBarButtonItem* bi = [[UIBarButtonItem alloc]
                       initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL];
bi.style = UIBarButtonItemStyleBordered;
[tbitems addObject:bi];
[bi release];

bi = [[UIBarButtonItem alloc]
      initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[tbitems addObject:bi];
[bi release];

bi = [[UIBarButtonItem alloc]
      initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
bi.style = UIBarButtonItemStyleBordered;
[tbitems addObject:bi];
[bi release];

tb.items = tbitems;

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tb];

[tb release];

这在Portrait中效果很好但是在Landscape中效果不是很好!最后有一个差距,我无法弄清楚如何填补空白!

gap

0 个答案:

没有答案