// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
[super loadView];
UIToolbar *toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlackTranslucent;
// create a bordered style button with custom title
UIBarButtonItem *playItem = [[[UIBarButtonItem alloc] initWithTitle:@"Play"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(playAction:)] autorelease];
UIBarButtonItem *emailItem = [[[UIBarButtonItem alloc] initWithTitle:@"Tell a Friend"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(emailAction:)] autorelease];
NSArray *items = [NSArray arrayWithObjects:
playItem,
emailItem,
nil];
toolbar.items = items;
// size up the toolbar and set its frame
// please not that it will work only for views without Navigation toolbars.
[toolbar sizeToFit];
CGFloat toolbarHeight = [toolbar frame].size.height;
CGRect mainViewBounds = self.view.bounds;
[toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),
CGRectGetWidth(mainViewBounds),
toolbarHeight)];
[self.view addSubview:toolbar];
}
- (void)playAction:(id)sender {
//some code
}
- (void)emailAction:(id)sender {
//some code
}