I'm adding a UIView
in the current UIViewController
. I need to remove a UIView
when touched anywhere on the screen. I have a UIButton
in the UIView
. But if I click UIButton
then also the UIView
is removed.
Actually I have added a button(Signout) in UIView
which when click should dismiss the currentview
and go to homeViewController
. But if I tap anywhere on the current view other than the button on UIView
then UIView
should be removed. But in my case if I click button then also UIView
is removed.
logout= [[UIView alloc]initWithFrame:CGRectMake(210,lbllogin.frame.origin.y+lbllogin.frame.size.height, 80, 50)];
logout.backgroundColor = [UIColor yellowColor];
btnSignout = [UIButton buttonWithType:UIButtonTypeCustom];
[btnSignout addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
btnSignout = CGRectMake(0,0,80,13);
[logout addSubview: btnSignout];
[self.view addSubview:logout];
UIButton *btnsignout=[[UILabel alloc]init];
[lblsignout setFrame:CGRectMake(0, 0, 80, 13)];
lblsignout.textAlignment = NSTextAlignmentLeft;
lblsignout.backgroundColor = [UIColor clearColor];
lblsignout .font=[UIFont fontWithName:@"Helvetica-Bold" size:14];
lblsignout.text=@"Sign out";
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[logout removeFromSuperview];
}