Reputation: 641
In my application i have a view in that i have many UIElements, buttons, etc..
I need to set
UserInteractionEnabled:NO for all the ui elements in that view except
one button.
I tried with
[self.view setUserInteractionEnabled:NO];
The Require button also the subview that self.view that button also apply same behavior.
I can able to apply individually but it is not a good way.
How should i set UserInteractionEnabled:NO for all the other ui elements except one
button
Upvotes: 4
Views: 5617
Reputation: 641
for (UIView *view in [self.view subviews])
{
if (view.tag==101)
[ view setUserInteractionEnabled:YES];
else
[ view setUserInteractionEnabled:NO];
}
Upvotes: 3
Reputation: 520
You can just add transparent subview in the front of your view and place button on this transparent view:
UIView* maskView = [[UIView alloc] initWithFrame:self.view.bounds];
maskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:maskView];
[maskView addSubview:buttonView];
And be sure that this transparent view is the last added subview, or just push it to the front of view in viewWillAppear:
[self.view bringSubviewToFront:maskView];
Upvotes: 1
Reputation: 3607
Check this out:
for (UIView *view in self.view.subviews) {
if (!([view class]==[UIButton class]) )
{
view.userInteractionEnabled = NO;
}
}
Upvotes: 1