Objective c 正在尝试将子视图添加到导航栏
我尝试的是:Objective c 正在尝试将子视图添加到导航栏,objective-c,ios7,uiview,uinavigationbar,Objective C,Ios7,Uiview,Uinavigationbar,我尝试的是: UIView *view = [[UIView alloc] initWithFrame:frame]; [view setBackgroundColor:[UIColor redColor]]; [[UINavigationBar appearance] addSubview:view]; // does't work [self.navController.view addSubview:view]; // does't work [self.nav
UIView *view = [[UIView alloc] initWithFrame:frame];
[view setBackgroundColor:[UIColor redColor]];
[[UINavigationBar appearance] addSubview:view]; // does't work
[self.navController.view addSubview:view]; // does't work
[self.navController.view bringSubviewToFront:view]; //
问题是如何在iOS7中正确地将子视图添加到导航栏中?谢谢你的建议
UPD0:对不起,伙计们。我得到了一部分。这是因为我在设置外观
之后有了self.navController.navigationBarHidden=YES
。嗯,似乎有一张脸的导航很有趣。酒吧执行。navigationBarHidden
在每个视图中都有自定义导航。酒吧。我应该深入了解细节。无论如何,谢谢你的回复
UPD1:只是继续搜索解决方案,将自定义视图添加到导航。条形背景图像。您必须将其添加到导航栏,请尝试以下操作:
[self.navigationController.navigationBar addSubview:view];
我是这样做的:
在我的主视图控制器中,我以主视图控制器作为委托初始化UINavigationController(主视图需要实现UINavigationControllerDelegate):
导航控制器将自动创建UINavigationBar。还可以通过此导航控制器将子视图添加到UINavigationBar。下面是我如何添加子视图的:
UIView *buttonsView = [[UIView alloc] initWithFrame:buttonsFrame];
button = [self buttonWithName:@"crop" target:self selector:@selector(cropImage) left:left];
[buttonsView addSubview: button];
...
self.navigationItem.titleView = buttonsView;
仅此而已。没有此类字段
navController
navController
可能是询问者的self
类的属性,未显示。提问者没有发布课程,所以我们不能确定,只是猜测。
UIView *buttonsView = [[UIView alloc] initWithFrame:buttonsFrame];
button = [self buttonWithName:@"crop" target:self selector:@selector(cropImage) left:left];
[buttonsView addSubview: button];
...
self.navigationItem.titleView = buttonsView;