Sometimes we require a vertical toolbar in ipad because we don’t have any controller for this. This code give you a vertical toolbar.
This is the .h file for toolBar
ToolBar.h->
@interface toolBar : UIView
{
CGPoint origin_;
UISegmentedControl* SegmentedControl_;
NSArray* SegmentImageArray_;
}
- (id) initWithOrigin:(CGPoint) origin;
- (void) makeToolBar;
@end
ToolBar.m file->
#import "toolBar.h"
@implementation toolBar
- (id) initWithOrigin:(CGPoint) origin
{
self = [super init];
if (self)
{
// This set the position where you want to display the toolbar
origin_ = origin;
self.frame = CGRectMake(origin_.x, origin_.y, 50, 748);
// this will create the toolbar
[self makeToolBar];
}
return self;
}
- (void) makeToolBar
{
SegmentImageArray_ = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"],
[UIImage imageNamed:@"8.png"],
[UIImage imageNamed:@"9.png"],
[UIImage imageNamed:@"10.png"], nil];
SegmentedControl_ = [[UISegmentedControl alloc] initWithItems:SegmentImageArray_];
SegmentedControl_.frame = CGRectMake(0, 0, 748, 50);
SegmentedControl_.segmentedControlStyle = UISegmentedControlStyleBezeled;
SegmentedControl_.momentary = 0;
[SegmentedControl_ addTarget:self action:@selector(SegmentControlAction:)
forControlEvents:UIControlEventValueChanged];
// This is where you set your toolbar control
CGAffineTransform SegmentTransform =
CGAffineTransformMake(0, 1, -1, 0, -348, 349);
SegmentedControl_.transform = SegmentTransform;
[self addSubview:SegmentedControl_];
}
- (void) SegmentControlAction:(id) sender
{
UISegmentedControl *segmentedControl =
(UISegmentedControl *)sender;
switch ([segmentedControl selectedSegmentIndex])
{
case 0:
{
//Action for first toolbar item
break;
}
case 1:
{
//Action for Second toolbar item
break;
}
case 2:
{
//Action for third toolbar item
break;
}
case 3:
{
//Action for fourth toolbar item;
break;
}
case 4:
{
//Action for fifth toolbar item
break;
}
case 5:
{
//Action for sixth toolbar item
break;
}
case 6:
{
//Action for seventh toolbar item
break;
}
case 7:
{
//Action for eight toolbar item
break;
}
case 8:
{
//Action for ninth toolbar item;
break;
}
case 9:
{
//Action for tenth toolbar item
break;
}
default:
break;
}
}
- (void)dealloc
{
[SegmentedControl_ release];
SegmentedControl_ = nil;
[SegmentImageArray_ release];
SegmentImageArray_ = nil;
[super dealloc];
}
@end