Can I subclass UIMenuController so that it can take icons instead of just text?
How would one go 开发者_JAVA百科about doing this? I'm looking for a dense, purely graphical menu on tap-hold.
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 ;)
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!
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
精彩评论