How can I add the 'Glow effect' to UIBarButtonItem?

后端 未结 2 772
旧巷少年郎
旧巷少年郎 2021-01-14 05:25

I tried a lot to find out the glow effect for UIBarButtonItem. Now am doing by creating a UIButton and making it as the customView for the UIBarButton. Do anyone have any o

2条回答
  •  耶瑟儿~
    2021-01-14 06:17

    You mean the effect you get when you touch an button? That is a property on an UIButton (also accessible from Interface Builder);

    @property(nonatomic) BOOL showsTouchWhenHighlighted
    

    So...

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.showsTouchWhenHighlighted = YES;
    

    If you write a subclass of UIBarButtonItem and put this code in there somewhere it is really easy (and not messy) to re-use it. I'm not sure if there is any other way.

提交回复
热议问题