Is it possible to customize the color of a UIMenuController?

扶醉桌前 提交于 2019-11-28 01:37:14

问题


The default background color is black. How can I change the color, similar to tintColor for navigation bars?


回答1:


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.




回答2:


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];



回答3:


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.



来源:https://stackoverflow.com/questions/5466570/is-it-possible-to-customize-the-color-of-a-uimenucontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!