Making a custom Button using a UIView or overriding UIButton?

前端 未结 3 1465
天涯浪人
天涯浪人 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:00

    An easy way to do this, is to override a UIView. In the view you add a UIButton as Subview. This way you have a reusable class without the need to re-implement button behaviour.

    You can style your button the way you want in the initWithFrame method of your UIView derived class. If you use this class as target for your button events, you can implement special behaviour easily, like showing the image.

    For the two pieces of text, you create two labels and add them as subviews to the button.

提交回复
热议问题