Can UIMenuItem show UIImage?

2020-04-28 03:52发布

问题:

I saw that it's possible — iBooks application does it.

Is it any way to do it?

回答1:

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/UIMenuItem-CXAImageSupport



回答2:

There is nothing in the current official API do that. UIMenuItem can only be initialised with -initWithTitle:action:

I suspect that Apple either using a private API or have implemented a custom control. Probably the former.

Asked previously here



回答3:

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!