开发者

Is it possible to customize the color of a UIMenuController?

开发者 https://www.devze.com 2023-02-20 05:01 出处:网络
The default b开发者_开发百科ackground color is black. How can I change the color, similar to tintColor for navigation bars?A possible solution to change the text color consists in using the appearance

The default b开发者_开发百科ackground color is black. How can I change the color, similar to tintColor for navigation bars?


A possible solution to change the text color consists in using the appearance proxy of the UIButton inside the UIMenuController. The thing is it uses directly the private UIButton subclass used by Apple in the Menu Controller. I would never recommend to access a private Apple class (and furthermore through its name), but in that specific Menu Controller color customization case I think that's the best solution. It lets you define the clean way your view appearances.

Swift

(NSClassFromString("UICalloutBarButton")! as! UIButton.Type).appearance().setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)

Objective-C

[[NSClassFromString(@"UICalloutBarButton") appearance] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];


I'm pretty sure this is not possible. You may be able to work something out if you subclass it.

EDIT: I took a look at the UIMenuController.h file and there don't seem to be any obvious ways to change the color. It is a subclass of NSObject if that helps you. Also, if you take a look at how people subclass UITabBarController to change it's color you may be able to work out a similar solution.


You can set the background color of UIMenuController like this -

Objective-C

[[NSClassFromString(@"UICalloutBarButton") appearance] setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8]];

Make sure that you use a color with transparency/alpha, otherwise it will throw an error.

0

精彩评论

暂无评论...
验证码 换一张
取 消