I had this same sort of issue when I wanted to do a custom button. I also have read many posts that don't seem to hit on the right way to subclass UIButton
. In your case, I would recommend subclassing UIButton
and override the setHighlighted:
method for adjusting the button on selection. I have a subclass of UIButton
called LDGradientButton
that can be found at lightdesign/LDGradientButton. Feel free to take a look at the drawing code. In my case, I was using CALayers
, but if I was doing it over, I'd probably use CoreGraphics
.
Create UIButton LIKE control with custom drawRect code
-
30-06-2022 - |
سؤال
I would like to create a custom shape that acts like a UIButton
. I need it to send touchUpInside
to a target like a button however I want to use drawRect
to change the button appearance when the buttons state changes.
I've read a lot of conflicting things on the net about not subclassing UIButton
or UIControl
.
So what it the acceptable way to do this?
Also if the answer is
UIControl
then how do you implementtouchUpInside
using the 'beginTracking
' methods?Why can't we subclass
UIButton
. I've read things about it been a class cluster and not usingUIButtonTypeCustom
because it will not work but why is this?
I hope someone could shed some light on this or point me to some good reading.
Thank you.
المحلول
لا تنتمي إلى StackOverflow