0

I want a Panel that contains colors to be a UIVisualEffectView. So, blur background and buttons. Like this: enter image description here

Should I create a ColorPanelView class that extends UIVisualEffectView (or UIView?) or a ColorPanel class that uses a UIVisualEffectView?

What are the differences and which way is better?

draern
  • 332
  • 3
  • 8
  • This relates to one of the most important rules for modern OO class design. "Composition over inheritance". https://en.m.wikipedia.org/wiki/Composition_over_inheritance – Darko Apr 07 '16 at 23:39

2 Answers2

1

If I understand correctly, you're asking if you should make a custom view that subclasses UIVisualEffectView or if you should just add a UIVisualEffectView to an existing view.

If my understanding is correct, then the answer depends on if you need to reuse this view anywhere else in your code. By making a custom subclass of UIVisualEffectView that has your panels on it, you can easily reuse it without repeating much code.

If you know you'll only need it once, you can just add a UIVisualEffectView to an existing view and then customize it the way you want it.

LulzCow
  • 1,199
  • 2
  • 9
  • 21
1

Either will work.

In this case I would just extend UIView instead of UIVisualEffectView. The reason being is that if the design changes and you want the color panel to be on a solid background instead of a blurred background, you can make that change without changing the class you're extending from.

picciano
  • 22,341
  • 9
  • 69
  • 82