Skip to content

Instantly share code, notes, and snippets.

@hunk
Created January 19, 2012 02:17
Show Gist options
  • Save hunk/1637220 to your computer and use it in GitHub Desktop.
Save hunk/1637220 to your computer and use it in GitHub Desktop.
custom buttons NavigationBar
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Root view";
UIButton *backImage = [UIButton buttonWithType:UIButtonTypeCustom];
backImage.frame = CGRectMake(0, 0, 24, 24);
backImage.backgroundColor = [UIColor clearColor];
[backImage setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[backImage addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithCustomView:backImage] autorelease];
self.navigationItem.leftBarButtonItem = backButton;
UIButton *clockButton = [UIButton buttonWithType:UIButtonTypeCustom];
clockButton.frame = CGRectMake(0, 0, 24, 24);
clockButton.backgroundColor = [UIColor clearColor];
[clockButton setBackgroundImage:[UIImage imageNamed:@"clock.png"] forState:UIControlStateNormal];
UIButton *calButton = [UIButton buttonWithType:UIButtonTypeCustom];
calButton.frame = CGRectMake(27, 0, 24, 24);
calButton.backgroundColor = [UIColor clearColor];
[calButton setBackgroundImage:[UIImage imageNamed:@"cal.png"] forState:UIControlStateNormal];
UIButton *resizeButton = [UIButton buttonWithType:UIButtonTypeCustom];
resizeButton.frame = CGRectMake(54, 0, 24, 24);
resizeButton.backgroundColor = [UIColor clearColor];
[resizeButton setBackgroundImage:[UIImage imageNamed:@"resize.png"] forState:UIControlStateNormal];
UIView *myToolBar = [[UIView alloc] init];
myToolBar.frame = CGRectMake(0, 0, 81, 24);
[myToolBar addSubview:clockButton];
[myToolBar addSubview:calButton];
[myToolBar addSubview:resizeButton];
UIBarButtonItem *toolBarButton = [[[UIBarButtonItem alloc] initWithCustomView:myToolBar] autorelease];
self.navigationItem.rightBarButtonItem = toolBarButton;
// Do any additional setup after loading the view, typically from a nib.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment