我想添加一个UIButton到UITabBar我用下面的代码iPad应用:添加的UIButton到UITabBar
TabBarAppDelegate *delegate = (TabBarAppDelegate *)[[UIApplication sharedApplication] delegate];
UITabBarController *tabbar = (UITabBarController *)delegate.window.rootViewController;
UIButton *b = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
[tabbar.view addSubview:b];
tabbar
是确定并引用到正确的TabBar项目(比如,我可以切换活动标签代码如下:[tabbar setSelectedIndex:1];
)。
此代码由其他一些自定义按钮调用。虽然有日志中没有错误,按键上不使用TabBar :(
表明我在做什么错的,什么是添加的UIButton到UITabBar正确的方式:)下面是一个例子:
http://gyazo.com/99fc0df0ed47dd6be91b558161cab4f9.png
在此先感谢!
编辑:好吧,如果我坚持使用UIToolbar选项,那么在视图之间切换的正确方法是什么?创建一个ViewContollers的NSArray并将相应的ViewController的视图加载到活动的View?
为什么要添加一个按钮?你想添加一个新标签吗? – Saphrosit
不,我真的需要添加一个自定义的UIButton。这就是我的客户想要的...这个按钮不是TabBarItem,它只是一个tabbar内的按钮:http://gyazo.com/99fc0df0ed47dd6be91b558161cab4f9.png – WASD42
@ WASD42:这看起来像我'UIToolBar'不是'UITabBar ',并且您可以轻松地将按钮添加到前者。 – PengOne