Giter VIP home page Giter VIP logo

uimenuitem-cxaimagesupport's Introduction

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.

uimenuitem-cxaimagesupport's People

Contributors

cxa avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.