Create UIActionsheet with custom size

Go To StackoverFlow.com

2

i m trying to make a actionsheet with UIDatepicker , this action sheet is open when the button click, i want to make action sheet like popover, but that can't work

 UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Pick Value"
                                                      delegate:self
                                             cancelButtonTitle:@"Done"
                                        destructiveButtonTitle:nil
                                             otherButtonTitles:nil];

    UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,180,0,0)];

    [menu addSubview:pickerView];
    [menu showInView:self.view.superview];

    //Change the height value in your CGRect to change the size of the actinsheet
    [menu setBounds:CGRectMake(0,0,400,400)];

    [pickerView release]; 
    [menu release]; 

problem is here that only one line Action sheet show , that not bound 400*400 what i need to do ??

2012-04-04 07:34
by roshni


0

UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Pick Value"
                                                  delegate:self
                                         cancelButtonTitle:@"Done"
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];

UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,180,0,0)];

[menu addSubview:pickerView];
[menu showInView:self.view.superview];

[menu setFrame:CGRectMake(0,0,320,400)]; //used setFrame instread of setBounds

[pickerView release]; 
[menu release]; 
2012-04-04 07:39
by Hemang
that's not work i still face same proble - roshni 2012-04-04 07:50
@roshni, now try thi - Hemang 2012-04-04 07:51
i have been try same thing but second ans guide me that tht's not work in ipad app - roshni 2012-04-04 07:55


0

I have tried your code and setBounds changes size of action sheet in my case.

Anyway you can also try to change sheet's frame in delegate's method

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet

It'll ensure that action sheet is already created at the moment when you're trying to update the frame.

2012-04-04 07:54
by RomanN


0

DO this on .m file

UIViewController *popoverContent = [[UIViewController alloc]init];
UIView *popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];

    datepiker= [[UIDatePicker alloc]init];
    [datepiker setFrame:CGRectMake(0, 0, 320, 216)];
    datepiker.datePickerMode=UIDatePickerModeDateAndTime;
    datepiker.hidden=NO;
    datepiker.minimumDate=[NSDate date];

    [self.view addSubview:datepiker];

    [datepiker release];
   // [datepiker addTarget:self action:@selector(changedDate:) forControlEvents:UIControlEventValueChanged];

    btn_add=[[UIButton alloc]initWithFrame:CGRectMake(115, 250, 100, 30)];
    [btn_add setTitle:@"Add" forState:UIControlStateNormal];
    [btn_add setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
    [btn_add setBackgroundColor:[UIColor redColor]];
    [btn_add addTarget:self action:@selector(AddDate:) forControlEvents:UIControlEventTouchUpInside];
    [popoverView addSubview:btn_add];

    btn_cancel=[[UIButton alloc]initWithFrame:CGRectMake(115, 300, 100, 30)];
    [btn_cancel setTitle:@"Cancel" forState:UIControlStateNormal];
    [btn_cancel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
    [btn_cancel setBackgroundColor:[UIColor redColor]];
    [btn_cancel addTarget:self action:@selector(CancelDate:) forControlEvents:UIControlEventTouchUpInside];
    [popoverView addSubview:btn_cancel];

    [popoverView addSubview:datepiker];
    [popoverView addSubview:btn_add];
    popoverContent.view = popoverView;
    popoverContent.contentSizeForViewInPopover = CGSizeMake(320,350);

    self.popoverController = [[UIPopoverController alloc]
                                  initWithContentViewController:popoverContent];
    [self.popoverController  presentPopoverFromRect:CGRectMake(400,-150, 320,220) 
                                                 inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
        }

    [popoverView release];
    [popoverContent release];

}

-(void)AddDate:(id)sender
{
}
-(void)CancelDate:(id)sender
{
[popoverController dismissPopoverAnimated:YES];

}

DO this on .h file and add UIPickerViewDelegate,UIPopoverControllerDelegate

{
UIPopoverController *popoverController;
UIDatePicker *datepiker;
UIPickerView *picker;
UIButton *btn_add;
UIButton *btn_cancel;
}
@property(nonatomic,retain)IBOutlet UIDatePicker *datepiker;
@property(nonatomic,retain)IBOutlet UIPickerView *picker;
@property(nonatomic,retain)UIPopoverController *popoverController;
@property(nonatomic,retain)UIButton *btn_add;
@property(nonatomic,retain)UIButton *btn_cancel;
-(void)AddDate:(id)sender;
-(void)CancelDate:(id)sender;

this works for me . Njoy

2012-04-04 07:59
by ChintaN -Maddy- Ramani
@chintu thank' - roshni 2012-04-04 08:02
@roshni Njoy : - ChintaN -Maddy- Ramani 2012-04-04 08:04
Ads