Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

iphone - Add UIView as subView on UIActionSheet

I am working on project where I want to show UIActionsheet with three buttons Change,Cancel and Done and at the place of title I want to put UIView which has some labels. I have created dynamic UIView and I added it to actionsheet but its hiding behind buttons I tried it by all possible ways to setFrame,bounds but I am not able to find solution. I want to place this UIView at the top of UIActionsheet followed by buttons. If you have any doubts feel free to post comments.

Here is My Code:

-(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];
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use this method, it will move all the buttons down by 100 pixels, please note that this type of modificaiton may result in your application rejection

-(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];
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...