Skip to content

Krishna03/UIMenuItem-CXAImageSupport

 
 

Repository files navigation

UIMenuItem with Image Support

Image item screenshot

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.

Make a category instead of subclassing UIMenuItem gains more flexibility. Yes, I mean you can add image to awsome PSMenuItem too!

How to use

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;

Limitation

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.

Creator

License

Under the MIT license. See the LICENSE file for more information.

About

UIMenuItem with Image Support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published