Making a custom Button using a UIView or overriding UIButton?

前端 未结 3 1475
天涯浪人
天涯浪人 2020-12-10 16:35

I need to generate a custom button through code, this is how i am currently doing it.

-(void) initialiseButtons 
{
    int ypos = playerImage.frame.origin.y          


        
3条回答
  •  醉话见心
    2020-12-10 17:22

    Personally, I would subclass UIButton. Despite all the talk that you can't subclass UIButton, Apple even talks about subclassing UIButton in the UIButton documentation.

    In the subclass I would create a UIView with the two labels (or images or whatever) and add them as subviews to the button (be sure to set interactive for the text and view as FALSE).

    What is awesome about this is that it leverages the UIButton code and keeps you from reinventing the wheel.

提交回复
热议问题