I have a UIControl
subclass that changes appearance and size when touched, a bit like the button of an iOS keyboard turns into the typewriter hand when touched:
I’m not sure how to write it. The idea is to draw a different shape when the default button shape is highlighted:
+---+
| |
+---+ | |
| | -> touch -> | |
+---+ +---+
But since the default button is smaller than the highlighted shape, the bigger shape gets clipped. I have considered these options:
Is there a best practice for this scenario?
Here are a few approaches:
You can draw outside the frame, you just have to make sure that myView.clipsToBounds
is False
. This would allow you to draw outside the bounds of the view inside another view and draw whatever extra content you would like.
That is probably the cleanest solution, but is also a bit "hacky" in my opinion. The other approach would be dirty (as you said) and to reset the frame size.
The last approach would be to create another view (the key pressed down) and throw it on top of the original (unpressed key) view.
All in all, it really comes down to what you're drawing / showing inside your view.