Lumialxk
Lumialxk

Reputation: 6369

How to make view highlight like table view cell

I have a view with many subviews. I want all the views highlighted when user taps. I know I can loop through subviews and highlight them. But it's not elegant. So what's the best way I can achieve this. Any ideas?

Upvotes: 0

Views: 335

Answers (3)

Saurabh Jain
Saurabh Jain

Reputation: 1698

Create a custom class of UIView and follow the code:

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    self.backgroundColor=[UIColor YourColor];
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    self.backgroundColor=[UIColor PreviousColor];
}

Upvotes: 0

Fonix
Fonix

Reputation: 11597

Do the subviews have a different colour to the parent view? if not, then rather make the subviews backgrounds transparent, then when you need to highlight it, just highlight the parent view.

Upvotes: 1

Fujia
Fujia

Reputation: 1242

Create an array containing all the views that should be highlighted. Then loop through the array to highlight them when needed.

Upvotes: 0

Related Questions