drawRect not called for custom UIButton subclass when highlighted

后端 未结 3 1028
暖寄归人
暖寄归人 2021-01-03 10:09

When using drawRect for a custom UIButton subclass, it never seems to get called to draw the button when highlighted. Do I need to call setNeedsDisplay for my button in my

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-03 10:36

    I found an easy solution.

    Just add the following method to your UIButton subclass:

    -(void)setHighlighted:(BOOL)highlighted
    {
        [super setHighlighted:highlighted];
        [self setNeedsDisplay];
    }
    

    That's it!

提交回复
热议问题