是否可以自定义 UIMenuController 的颜色?
默认背景颜色为黑色。如何更改颜色,类似于导航栏的 tintColor
?
The default background color is black. How can I change the color, similar to tintColor
for navigation bars?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更改文本颜色的一个可能的解决方案是使用 UIMenuController 内 UIButton 的外观代理。问题是它直接使用 Apple 在菜单控制器中使用的私有 UIButton 子类。我永远不会建议访问私有 Apple 类(而且还通过其名称),但在特定的菜单控制器颜色自定义情况下,我认为这是最好的解决方案。它可以让您定义查看外观的清晰方式。
Swift
Objective-C
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
Objective-C
我很确定这是不可能的。如果你对它进行子类化,你也许能够解决一些问题。
编辑:我查看了 UIMenuController.h 文件,似乎没有任何明显的方法可以更改颜色。如果对您有帮助的话,它是 NSObject 的子类。另外,如果您看看人们如何子类化 UITabBarController 来更改其颜色,您也许可以找到类似的解决方案。
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.
您可以像这样设置 UIMenuController 的背景颜色 -
Objective-C
确保您使用具有透明度/alpha 的颜色,否则会引发错误。
You can set the background color of UIMenuController like this -
Objective-C
Make sure that you use a color with transparency/alpha, otherwise it will throw an error.