UIActionSheet on iPad frame too small

前端 未结 2 496
傲寒
傲寒 2020-12-31 08:19

I am trying to display a UIActionSheet on the iPad with a UIPickerView in it, I have the equivalent code working for iPhone so my UIPickerVie

2条回答
  •  一整个雨季
    2020-12-31 08:30

    I managed to make it work using a silly way.

    For your reference:
    Setup PickerView.

    UIActionSheet's width can't be adjusted somehow, so have to adjust pickerView accordingly. Height wise, you can adjust with the amount of "\n" in actionSheet title.

    UIDatePicker * pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 270, 220)];
    pickerView.datePickerMode = UIDatePickerModeDate; 
    
    UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n\n" delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];    
    
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    [actionSheet addSubview:pickerView];
    [actionSheet showFromRect:button.frame inView:button.superview animated:YES];
    [actionSheet release];
    

    Set Frame or Bound doesn't work for me.

    [actionSheet setBounds:pickerView.frame];   
    [actionSheet setFrame:pickerView.frame];
    



    Agreed on using UIPopoverController, but don't know why, it got a serious UI delay when I put UIDatePickerView into popover (it took almost 1 sec lag to pop up) which I can't find the root cause. So have to fallback to above method.


    Happy Coding.

提交回复
热议问题