Trying to add subview to navigation bar

What I tried:

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]; // 

The question is, how can we properly add subview to our navigation bar in iOS7? Thanks for the consultation.

UPD0: Sorry guys. I got it in part. This happened because I have self.navController.navigationBarHidden = YESafter setupAppearance. Well, it looks like one face with an interesting nav. bar. navigationBarHiddenand in each view we have a custom nav. bar. I have to dive into the details. Anyway, thanks for the answer.

UPD1: just continue the search solution to add a custom view to the navigation. as background image.

+4
source share
2 answers

, :

[self.navigationController.navigationBar addSubview:view];
+8

: UINavigationController ( UINavigationControllerDelegate):

self.nav = [[UINavigationController alloc] initWithRootViewController: self];

UINavigationBar. subviews UINavigationBar, contoller. subview:

UIView *buttonsView = [[UIView alloc] initWithFrame:buttonsFrame];
button = [self buttonWithName:@"crop" target:self selector:@selector(cropImage) left:left];
[buttonsView addSubview: button];
...
self.navigationItem.titleView = buttonsView;

.

+1

Source: https://habr.com/ru/post/1538258/


All Articles