The navigation bar is set programmatically.
The display name is set as follows. < p>
self.title = NSLocalizedString(name,@“”);
The name depends on the displayed view.
Now I want to be on the navigation bar Show a small icon, it also depends on the view.
How do I do it?
Enter didFinishLaunchingWithOptions
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title_bar.png"] forBarMetrics:UIBarMetricsDefault];
Or you can Use any view to set the navigation bar image
UINavigationBar *navBar = [[self navigationController] navigationBar];
UIImage *image = [UIImage imageNamed:@"TopBar.png "];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
Or you can set the view on the NavigationBar Link
[[UINavigationBar appearance] addSubview:yourView];
or
self.navigationItem.titleView = YourView;
and use h to set the title< /p>
self.navigationItem.title = @"Your Title";
You can use this to get the navigationBarButton
< pre>-(void)getRightBarBtn
{
UIButton *Btn =[UIButton buttonWithType:UIButtonTypeCustom];
[Btn setF rame:CGRectMake(0.0f,0.0f,68.0f,30.0f)];
[Btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@”yourImage.png”]] forState:UIControlStateNormal];
//[Btn setTitle:@”OK” forState:UIControlStateNormal];
//Btn.titleLabel.font = [UIFont fontWithName:@”Georgia” size:14];
[Btn addTarget:self action:@selector(yourBtnPress:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithCustomView:Btn];
[self.navigationItem setRightBarButtonItem:addButton];
}< /pre>
And set a simple imageView on the navigation bar
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"star.png" ]];
UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:image];
self.navigationItem.rightBarButtonItem = backBarButton;
I have A detailed view with a navigation bar, with a back button and view name.
The navigation bar is set programmatically.
The displayed name is set as follows.
self.title = NSLocalizedString(name,@“”);< /p>
The name depends on the displayed view.
Now I want to display a small icon on the navigation bar, which also depends on the view.
How do I do it?
You can set the backGround image as navigationBar to use this option
Enter didFinishLaunchingWithOptions
p>
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title_bar.png"] forBarMetrics:UIBarMetricsDefault];
Or you can use any view to set the navigation bar image
< p>
UINavigationBar *navBar = [[self navigationController] navigationBar];
UIImage *image = [UIImage imageNamed:@"TopBar.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
Or you can set the view on NavigationBar Link
[[UINavigationBar appearance] addSubview:yourView];
< p>Either
self.navigationItem.titleView = YourView;
and use h to set the title
self.navigationItem.title = @"Your Title";
You can use this to get the navigationBarButton
-(void)getRightBarBtn
{
UIButton *Btn =[UIButton buttonWithType:UIButtonTypeCustom];
[Btn setFrame:CGRectMake(0.0f,0.0f,68.0f,30.0f)];
[Btn setBackgroundI mage:[UIImage imageNamed:[NSString stringWithFormat:@"yourImage.png"]] forState:UIControlStateNormal];
//[Btn setTitle:@"OK" forState:UIControlStateNormal];
//Btn. titleLabel.font = [UIFont fontWithName:@"Georgia" size:14];
[Btn addTarget:self action:@selector(yourBtnPress:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithCustomView:Btn];
[self.navigationItem setRightBarButtonItem:addButton];
}
and set a simple imageView on the navigation bar
p>
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"star.png"]];
UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:image];
self.navigationItem.rightBarButtonItem = backBarButton;