Created
January 19, 2012 02:17
-
-
Save hunk/1637220 to your computer and use it in GitHub Desktop.
custom buttons NavigationBar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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