TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
UIMenuItem
uses UILabel
to display its title, that means we can swizzle -drawTextInRect:
to support image.
UIMenuItem+CXAImageSupport
is a dirty hack but should be safe in most cases. Contains no any private API.
Make a category instead of subclassing UIMenuItem
gains more flexibility. Yes, this category can be applied to the awesome PSMenuItem too!
Add UIMenuItem+CXAImageSupport.{h,m}
to your project.
The method names describe all. Default draws shadow as the text title. If you want to hide shadow, set hidesShadow
to YES
.
- (id)cxa_initWithTitle:(NSString *)title action:(SEL)action image:(UIImage *)image;
- (id)cxa_initWithTitle:(NSString *)title action:(SEL)action image:(UIImage *)image hidesShadow:(BOOL)hidesShadow;
- (void)cxa_setImage:(UIImage *)image forTitle:(NSString *)title;
- (void)cxa_setImage:(UIImage *)image hidesShadow:(BOOL)hidesShadow forTitle:(NSString *)title;
UIMenuItem+CXAImageSupport
uses UIMenuItem
's title to map related image since there is no any other clue of UIMenuItem
I can find to connect to UILabel
. You can't set different images for the same title.
Under the MIT license. See the LICENSE file for more information.