简体   繁体   中英

Can we add button on scroll view

I want to select multiple images from gallery and want to upload but before uploading I want to add a cancel button which help's user in deleting the image/image's after selection if user wants to. So how can I add a cancel button on image view ? I've tried the below code for adding button but when I select the multiple image's or single image then this button is not visible.

    UIImage *imgview1=(UIImage*)[UIImage imageNamed:@"overlay.png"];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    //[button addTarget:self  action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown];
    [button setImage:imgview1 forState:UIControlStateNormal];
    button.frame = CGRectMake(25, 25, 60, 60);
    [_scrollView addSubview:button];

I want to make the User Interface of the page like this image!

Unfortunately I can't comment yet, but could you provide a bit more clarification?

My understanding from the question is that you would like to have a scroll view with many buttons in it (the buttons will be selectable images), and on those buttons you would like to add an (x) button like in the image that will respond to taps.

If that is your question then I think the simplest answer is to add another button as a subview of the image when it is selected. When that subview button is tapped you can respond in a method like below:

(void)xTapped:(UIButton *)xButton
{
   UIButton *myImage = xButton.superview;
   // then unselect the superview here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM