0

我正在添加一个UIViewin UIActionSheet,我需要在视图上添加四个标签和一个关闭按钮。但我需要 UIactionSheet 从屏幕中心开始。当我调整尺寸时,我无法得到它。

-(IBAction)buttontapped:(id)sender{


     UIView    *showDetailsView = [[UIView alloc]initWithFrame:CGRectMake(0,10, 320, 260)];

        showDetailsView.backgroundColor = [UIColor whiteColor];

        UILabel  *name =[[UILabel alloc] init];
        [name setFrame:CGRectMake(10, 40,250, 50)];
        name.textAlignment = UITextAlignmentLeft;
        name.backgroundColor = [UIColor clearColor];
        name .font=[UIFont fontWithName:@"arial" size:12];
        name.text=@"Name";
        [showDetailsView addSubview:name];


        UIActionSheet *aac = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil  otherButtonTitles:@"Close", nil];
        aac.actionSheetStyle = UIActionSheetStyleAutomatic;
        [aac addSubview:showDetailsView];
        [aac setFrame:CGRectMake(0,0,320,400)];
        [aac showInView:self.view];

}

我可以看到它是从底部添加的,但它没有像下图那样扩展到屏幕中心:我需要增加它的高度。

4

4 回答 4

1

从 SO 的一个答案中,我得到了这种方法,它的作用就像魅力:)

-(void)setActionSheetHeight
{
    CGRect actionSheetRect = self.myActionSheet.frame;
    CGFloat orgHeight = actionSheetRect.size.height;
    actionSheetRect.origin.y -= 214; //height of picker
    actionSheetRect.size.height = orgHeight+214;
    self.myActionSheet.frame = actionSheetRect;

    [self.myPicker setShowsSelectionIndicator:YES];

    CGRect pickerRect = self.myPicker.frame;
    pickerRect.origin.y = orgHeight;
    self.myPicker.frame = pickerRect;
}

myActionSheet是一个UIActionSheetiVar。
myPicker是一个UIPickerViewiVar。
您可以设置所需的值,而不是214静态值,并根据该值设置UIActionSheet.

注意
必须在显示操作表之后调用,即在[self.myActionSheet showFromTabBar:self.tabBarController.tabBar];代码行之后。表示在调用show操作表上的方法之后。

于 2012-12-27T06:51:39.337 回答
0

When you present the actionsheet, you need to send appropriate message to present it. Refer to

showFromRect:inView:animated:

showInView:

For showInView:, you can have an invisible view with the bottom at mid-height of the view controller and top aligned to the top of viewcontroller.

For showFromRect:inView:animated:, if you have any UIView to which the actionsheet needs to be anchored, you can used it there.

于 2012-12-27T06:26:50.440 回答
0

用这个:

[aac setBounds:CGRectMake(0,0,320,400)];
于 2012-12-27T05:35:20.477 回答
0

UIActionSheet 设计为从屏幕底部呈现。

您只能在 ipad 的中心显示它......不能在 iphone 中显示。

您可以根据您的要求使用自定义警报视图。

https://github.com/alokard/BlockAlertView

于 2012-12-27T05:53:11.833 回答