1

我正在做一个项目,我想用三个按钮显示 UIActionsheet 更改、取消和完成,在标题的地方我想放置带有一些标签的 UIView。我创建了动态 UIView 并将其添加到操作表中,但它隐藏在按钮后面我尝试了所有可能的方法来设置框架,边界但我无法找到解决方案。我想将此 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];
}
4

1 回答 1

3

您可以使用此方法,它将所有按钮向下移动 100 像素,请注意这种类型的修改可能会导致您的申请被拒绝

-(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];
}
于 2012-06-15T13:41:53.190 回答