How to dismiss programmatically created UIView when user taps on any part of iPhone screen <p>I am working on an app where a popup view is created programatically. Now requirement is when user taps somewhere else than that popview, I want to remove that view from superview.</p> <p>Below is my code for creating view</p> <pre><code>- (IBAction)Morebtn:(id)sender { UIView *cv = [[UIView alloc]initWithFrame:CGRectMake(200, 60, 100, 80)]; UIButton *label1 = [[UIButton alloc]initWithFrame:CGRectMake(-50,2, 200, 30)]; [label1 setTitle: @"My Button" forState: UIControlStateNormal]; label1.titleLabel.font=[UIFont fontWithName:@"SegoeUI" size:12.0]; [label1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [cv addSubview:label1]; UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(5,20, 200, 30)]; label2.text = @"Mark as unread"; label2.font=[UIFont fontWithName:@"SegoeUI" size:12.0]; [cv addSubview:label2]; //add label2 to your custom view [cv setBackgroundColor:[UIColor grayColor]]; [self.view addSubview:cv]; } </code></pre> <p>Here is my screen shot of view <img src="https://i.stack.imgur.com/Mtzfu.png" alt="enter image description here"></p>