iPhone Graphics - Making a custom NavigationBar Button

Опубликовано: 23 Июнь 2026
на канале: MilmersXcode
4,747
16

In this tutorial you will learn how to make a custom UINavigationBarButton

UINavigationBarButton Background Sizes:
• 128x80 pixels - For Retina
• 64x40 pixels - For Normal

Main Code:

In .h:
-(void) back;

In .m - viewDidLoad:

UIImage *normalBackImage = [UIImage imageNamed:@"BackButton.png"];
//UIImage *higlightedBackImage = [UIImage imageNamed:@"back button pressed.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.bounds = CGRectMake( 0, 0, normalBackImage.size.width, normalBackImage.size.height );
[backButton setImage:normalBackImage forState:UIControlStateNormal];
//[backButton setImage:higlightedBackImage forState:UIControlStateHighlighted];
[backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *backBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backBarItem;
[backBarItem release];

-(void) back
{
[self.navigationController popViewControllerAnimated:YES];
}

Previous Video:    • iPhone Graphics-Setting Background image o...  
Playlist:    • Setting iPhone Graphics  

Jan-marteens channel:    / jm11081996  
Jans video tutorial:    • Video  

Twitter:   / failcakeapps  
Apple Developer Center: http://developer.apple.com/devcenter/...
Website: http://failcake.webs.com/
Channel:    / milmersxcode