添加的UIView作为UIActionSheet子视图(Add UIView as subView

2019-06-25 12:24发布

我对项目的工作,我想显示UIActionsheet有三个按钮更改,取消和完成,并在我想提出的UIView其中有一些标签标题的地方。 我已创建动态的UIView,我加入它actionsheet但其背后隐藏的按钮我尝试了所有可能的方式来SETFRAME,界限,但我无法找到解决方案。 我想这个地方在UIView的后面按钮UIActionsheet的顶部。 如果您有任何疑问,请随时发表评论。

这里是我的代码:

-(IBAction)tapbutton:(id)sender
{
Lablesubview *view = [[Lablesubview alloc]init];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                               delegate:self 
                                      cancelButtonTitle:@"Cancel" 
                                 destructiveButtonTitle:@"Change" 
                                      otherButtonTitles:@"Done",nil];

   [actionSheet addSubview:view];
   [actionSheet showInView:self.view];
}

Answer 1:

您可以使用此方法,它会将所有的按钮下降100个像素,请注意,这种类型的modificaiton可能导致您的申请遭拒

-(IBAction)tapbutton:(id)sender
{   
    //create the view
    Lablesubview *view = [[Lablesubview alloc]init];
    //Set the frame
    view.frame = CGRectMake(0, 10, 320, 100);
    view.backgroundColor = [UIColor greenColor];

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self 
                                                    cancelButtonTitle:@"Cancel" 
                                               destructiveButtonTitle:@"Change" 
                                                    otherButtonTitles:@"Done",nil];

    [actionSheet showInView:self.view];

    CGRect rect;

    //expand the action sheet
    rect = actionSheet.frame;
    rect.size.height +=100;
    rect.origin.y -= 100;
    actionSheet.frame = rect;

    //Displace all buttons
    for (UIView *vButton in actionSheet.subviews) {
        rect = vButton.frame;
        rect.origin.y += 100;
        vButton.frame = rect;
    }    


    //Add the new view
    [actionSheet addSubview:view];
}


文章来源: Add UIView as subView on UIActionSheet