Note that there are some explanatory texts on larger screens.

plurals
  1. POShow UIButton Done on UIScrollView for Images only when user taps on image view
    primarykey
    data
    text
    <p>How can i code for UIButton to show only when user taps on UIScrollView for images. </p> <pre><code> - (void)viewDidLoad { self.view.backgroundColor = [UIColor blackColor]; UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; imageScrollView.pagingEnabled = YES; NSInteger numberOfViews = 61; for (int i = 0; i &lt; numberOfViews; i++) { CGFloat xOrigin = i * self.view.frame.size.width; UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]; [myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside]; myButton.frame = CGRectMake(xOrigin, 10, 60, 35); [myButton.layer setMasksToBounds:YES]; [myButton.layer setCornerRadius:10.0f]; myButton.layer.borderWidth = 2; myButton.layer.borderColor = [[UIColor whiteColor] CGColor]; [myButton setTitle:@"Done" forState:UIControlStateNormal]; myButton.backgroundColor = [UIColor blackColor]; NSString *imageName = [NSString stringWithFormat:@"image%d.png", i]; UIImage *image = [UIImage imageNamed:imageName]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height); [imageScrollView addSubview:imageView]; [imageScrollView addSubview:myButton]; [imageView release]; } imageScrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height); [self.view addSubview:imageScrollView]; [imageScrollView release]; } </code></pre> <p>Right now it is displaying on every image view but i want it should Show UIButton Done only when taps on the screen.</p> <p>EDIT: If i add </p> <pre><code> [imageView addGestureRecognizer: tap]; </code></pre> <p>and initiate Gesturerecognizer</p> <pre><code> UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; tap.numberOfTapsRequired = 1; [self addGestureRecognizer:tap]; [tap release]; </code></pre> <p>then how can i code in handle tap method to show done button when user taps on image view</p> <pre><code> - (void)handleTap:(UIGestureRecognizer*)tap { } </code></pre> <p>Thanks for help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload