Change the state of a customized button (button with an image)?

前端 未结 6 2277
执笔经年
执笔经年 2021-02-11 09:34

I know how to change the state of the regular button, as well as change the background color of a regular button. However, when I do UIButton:setBackgroundImage (cu

6条回答
  •  無奈伤痛
    2021-02-11 10:12

    Why are you having the image cover the button rather than setting the background of the button to the image?

    EDIT: What you want to do is make your highlighted and/or selected state button have a different background, like this.

    UIImage* highlightImage = [UIImage imageNamed:@"highlightImage.png"];
    [b setBackgroundImage:highlightImage forState:UIControlStateSelected];
    

    Then in your event handler

    - (void)buttonOnclick
    {
       b.selected = !b.selected;
    }
    

提交回复
热议问题