Use this following code ..
-(void)actionSheetClicked
{
if(!self.modeOptions)
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Dummy",nil]; //Here I add dummy button for getting cancel button style.
self.modeOptions = actionSheet;
[actionSheet release];
}
self.modeOptions.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[self.modeOptions showFromTabBar:self.tabBarController.tabBar];//Here i show from tab bar, you can showfromview also
// [self.modeOptions setBounds:CGRectMake(0, 0, 320, 300)];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)//frame size for action sheet in both modes
{
[self.modeOptions setBounds:CGRectMake(0, 0, 320, 300)];
}
else
{
[self.modeOptions setBounds:CGRectMake(0, 0, 480,250)];
}
UIButton *buttonDum = (UIButton *)[[self.modeOptions subviews] objectAtIndex:0];
[buttonDum setHidden:YES];//hide dummy button..
UIButton *cancelButton = (UIButton *)[[self.modeOptions subviews] objectAtIndex:1];
if( !self.button1)
{
UIButton *Btn = [[UIButton alloc]initWithFrame:CGRectMake(80, 40, 70, 70)];//**Here I use 70 X 70 px image , you can edit it**
self.button1 = Btn;
[self.button1 addTarget:self action:@selector(invokeFirstBtn) forControlEvents:UIControlEventTouchUpInside];
[self.button1 setImage:[UIImage imageNamed:@"btn1Image.png"] forState:UIControlStateNormal];
[self.modeOptions addSubview:self.button1];
[Btn release];
}
if( !self.button2)
{
UIButton *Btn = [[UIButton alloc]initWithFrame:CGRectMake(180, 40, 70, 70)];//**Here I use 70 X 70 px image , you can edit it**
self.button2 = sharBtn;
[self.button2 addTarget:self action:@selector(invokeButton2) forControlEvents:UIControlEventTouchUpInside];
[self.button2 setImage:[UIImage imageNamed:@"btn2Image.png"] forState:UIControlStateNormal];
[self.modeOptions addSubview:self.button2];
[Btn release];
}
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)//frame size for action sheet in both modes
{
cancelButton.frame = CGRectMake(50, 140, 220, 40);
self.button1.frame = CGRectMake(65, 40, 70, 70);
self.button2.frame = CGRectMake(175, 40, 70, 70);
}
else
{
cancelButton.frame = CGRectMake(135, 140, 220, 40);
self.button1.frame = CGRectMake(155, 40, 70, 70);
self.button2.frame = CGRectMake(260, 40, 70, 70);
}
}
This is working code.. Check with this. You can change with frame size as your wish... You can create actionsheet without dummy button...