GithubHelp home page GithubHelp logo

queryfish / uimenuitem-cxaimagesupport Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cxa/uimenuitem-cxaimagesupport

0.0 2.0 0.0 278 KB

UIMenuItem with Image Support

License: MIT License

uimenuitem-cxaimagesupport's Introduction

UIMenuItem with Image Support

screenshot of UIMenuItem with image

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 APIs and should be safe for App Store.

How to use

Drag UIMenuItem+CXAImageSupport.{h,m} to your project.

The method names describe all. For simple usage, the only step is to set a image to the menu item. For advance usage, config and set a settings.

@class CXAMenuItemSettings;

@interface UIMenuItem (CXAImageSupport)

- (id)cxa_initWithTitle:(NSString *)title action:(SEL)action image:(UIImage *)image;
- (id)cxa_initWithTitle:(NSString *)title action:(SEL)action settings:(CXAMenuItemSettings *)settings;
- (void)cxa_setImage:(UIImage *)image;
- (void)cxa_setSettings:(CXAMenuItemSettings *)settings;

@end

// Uses a settings class instead of NSDictionary to avoid
   misspelled keys
@interface CXAMenuItemSettings : NSObject

+ (instancetype)settingsWithDictionary:(NSDictionary *)dict;

@property (nonatomic) UIImage *image;
@property (nonatomic) BOOL shadowDisabled;
@property (nonatomic) CGFloat shrinkWidth; // For adjustment item width only,
 will not be preciouse because menu item will keep its minimun width,
  it's useful for showing some large amount of menu items without expanding.

@end

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. You can't set different images for the same title.

Creator

License

UIMenuItem+CXAImageSupport is released under the MIT license. In short, it's royalty-free but you must you keep the copyright notice in your code or software distribution.

uimenuitem-cxaimagesupport's People

Contributors

cxa avatar

Watchers

James Cloos avatar steve wu 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.