biz*_*tes 7 objective-c uitoolbar ipad ios ios7
我有一个iPad应用程序的代码,适用于iOS 7以下的任何iOS
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 75, 44)];
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];
UIBarButtonItem *composeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(toggleDelete:)];
[buttons addObject:composeButton];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedSpace.width = 5;
[buttons addObject:fixedSpace];
UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(touchMe:)];
[buttons addObject:bi];
[tools setItems:buttons animated:NO];
tools.barStyle = -1;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[bi release];
[fixedSpace release];
[composeButton release];
[buttons release];
[tools release];
Run Code Online (Sandbox Code Playgroud)
iOS 7之前的结果是:
在iOS 7上运行时相同的代码结果如下:
由于某种原因,按钮被移动到iOS 7中工具栏的底部.
现在,我可以使用UIBarItem imageInset属性重新定位它们,但这似乎是一种hackish,因为那时我需要检查iOS版本,如果iPad运行iOS 7+,则只需要执行imageInset.我的问题是我是否遗漏了与UIToolbar有关的iOS 7的任何内容?我查看了iOS 7 UI过渡指南,找不到任何特定于此问题的内容.
由于我没有得到任何其他答案并为我找到了正确的解决方案,我将为遇到同样问题的其他人回答这个问题.如果您的目标是iOS 5.0及更高版本,则有一种方便的方法可以向右侧栏按钮添加多个项目.这是修复:
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:deleteButton, bi, nil]];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4692 次 |
最近记录: |