Can I subclass UIMenuController so that it can tak

2019-06-08 19:22发布

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

3条回答
淡お忘
2楼-- · 2019-06-08 20:16

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

查看更多
男人必须洒脱
3楼-- · 2019-06-08 20:16

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!

查看更多
孤傲高冷的网名
4楼-- · 2019-06-08 20:18

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

查看更多
登录 后发表回答