Can I subclass UIMenuController so that it can take icons instead of just text?

倾然丶 夕夏残阳落幕 提交于 2019-12-08 09:21:34

问题


How would one go about doing this? I'm looking for a dense, purely graphical menu on tap-hold.


回答1:


In 3.2 you can add menu items using the menuItems property. But I think subclassing won't be useful, since it's a singleton that does not returns the views of each menu item. You could access menuFrame when setMenuVisible:animated: is called, so you can add you're own view that looks like a menu items with icons. But for adding icons to the system menu items... I think you should stick to what's Apple is giving you ;)




回答2:


I wrote a category to support image for UIMenuItem. It's based on method swizzling, but should be safe in most cases.

https://github.com/cxa/CXAImageMenuItem

Note: duplicate answer to https://stackoverflow.com/a/14140904/395213

EDIT: the above link is 404'ed, this link works

https://github.com/cxa/UIMenuItem-CXAImageSupport




回答3:


My low reputation don't let me post links, therefore I am answering again here:

Check Emoji & Symbols, perhaps it will fit to your purpose.

Go to your Xcode Menu -> Edit -> Emoji & Symbols.

Ex.:

let menuItemYes = UIMenuItem(title: "✅", action: "doSomething")

Good luck!



来源:https://stackoverflow.com/questions/4414183/can-i-subclass-uimenucontroller-so-that-it-can-take-icons-instead-of-just-text

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