0
我有一个带有工具栏的导航栏控制器。工具栏左侧只有一个按钮:信息灯。当我将视图旋转到横向时,工具栏仍然存在,但按钮不见了。视图处于横向模式时工具栏上的信息灯消失
我该如何让它留下来。我在IB查看了我的struts工具栏。它们被设置为留在工具栏的左下角。
我正在使用基本SDK 4.0版的iPod touch进行测试。
下面是代码:
UIButton *info = [UIButton buttonWithType:UIButtonTypeInfoLight];
[info addTarget:self
action:@selector(infoTap:)
forControlEvents:UIControlEventTouchUpInside];
/** Allocate and initialize the information button on the leftside of the toolbar.
*/
UIBarButtonItem *infoItem = [[UIBarButtonItem alloc] initWithCustomView:info];
/** Use this to put space in before your info toolbar button.
*/
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
/** Add buttons to the array.
*/
NSMutableArray *items = [NSMutableArray arrayWithObjects: infoItem, flexItem, nil];
/** Add array of buttons to toolbar.
*/
[self.toolbar setItems:items animated:NO];
/** Add the toolbar as a subview to the navigation controller.
*/
[self.navigationController.view addSubview:toolbar];
有什么建议?
阿曼达
你为什么使用UIBarButtonSystemItemFlexibleSpace?如果按钮位于工具栏的最左侧,则不需要该按钮。 –