大佬教程收集整理的这篇文章主要介绍了ios – 将UINavigationBar添加到UIView中?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的代码:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,self.frame.size.width,headerHeight)]; [navBar setBACkgroundColor:[UIColor blueColor]]; [self addSubview:navBar]; UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithtitle:@"done" style:UIBarButtonItemStylePlain target:self action:@SELEctor(done:)]; UINavigationItem *navItem = [[UINavigationItem alloc] initWithtitle:@"categories"]; [navItem setrightBarButtonItem:doneItem animated:YES]; [navBar setItems:[NSArray arrayWithObject:navItem] animated:YES];
UIViewController *viewController = [[MenuViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController]; self.window.rootViewController=navController;
但是如果您有一个视图来呈现您想要的导航栏的新视图,则使用此视图显示新视图:
UIViewController *viewController = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController]; [self presentViewController:navigationcontroller animated:YES completion:nil];
那么您可以在第二个视图中添加navBarButton,如下所示:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundLeorNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundLeorNil]; if (self) { UIBarButtonItem *btnAdd = [[UIBarButtonItem alloc] initWithBarButtonSy@L_772_10@Item:UIBarButtonSy@L_772_10@ItemAdd target:self action:@SELEctor(btnAddGroupPressed)]; self.navigationItem.rightBarButtonItem=btnAdd; } return self; }
以上是大佬教程为你收集整理的ios – 将UINavigationBar添加到UIView中?全部内容,希望文章能够帮你解决ios – 将UINavigationBar添加到UIView中?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。