Git Product home page Git Product logo

uimenuitem-cxaimagesupport's Introduction

UIMenuItem with Image Support

Officially Deprecated! use MenuItemKit instead.

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

Xcode 7 required due to Objective-C generics.

Drag UIMenuItem+CXAImageSupport.{h,m} to your project. Or drag ImageMenuItem.xcodeproj to your project and embed ImageMenuItem framework if you only support iOS 8.0 and above.

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)

- (instancetype)initWithTitle:(NSString *)title action:(SEL)action image:(UIImage *)image;
- (instancetype)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 <NSCopying>

+ (instancetype)settingsWithDictionary:(NSDictionary<NSString *, id> *)dict;

@property (nonatomic, strong) UIImage *image;
@property (nonatomic) BOOL shadowDisabled;
@property (nonatomic, strong) UIColor * __nullable shadowColor; // Default is [[UIColor blackColor] colorWithAlphaComponent:1./3.]
@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.

About Me

  • Twitter: @_cxa
  • Apps available in App Store: http://lazyapps.com
  • PayPal: xianan.chen+paypal 📧 gmail.com, buy me a cup of coffee if you find it's useful for you.

License

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

uimenuitem-cxaimagesupport's People

Contributors

alexpopov avatar cxa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uimenuitem-cxaimagesupport's Issues

0.0.1

目前pod上边的版本依然是0.0.1,可能需要修改一下~

Please add semantic version tags

I’ve recently added UIMenuItem-CXAImageSupport to the CocoaPods package manager repo.

CocoaPods is a tool for managing dependencies for OSX and iOS Xcode projects and provides a central repository for iOS/OSX libraries. This makes adding libraries to a project and updating them extremely easy and it will help users to resolve dependencies of the libraries they use.

However, UIMenuItem-CXAImageSupport doesn't have any version tags. I’ve added the current HEAD as version 0.0.1, but a version tag will make dependency resolution much easier.

Semantic version tags (instead of plain commit hashes/revisions) allow for resolution of cross-dependencies.

In case you didn’t know this yet; you can tag the current HEAD as, for instance, version 1.0.0, like so:

$ git tag -a 1.0.0 -m "Tag release 1.0.0"
$ git push --tags

can not show text and image both

hello i write in your demo like this
UIMenuItem *item1 = [[UIMenuItem alloc] initWithTitle:@"noImage" action:@selector(itemClick)];
UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"haveIamge" action:@selector(itemClick) image:[UIImage imageNamed:@"camera"]];
[UIMenuController sharedMenuController].menuItems = @[item1, item2];
i want like this like in APP WeRead

image(above)
text (below)

Xcode 7GM + OSX 10.11

Hi @cxa ,
compiling under Xcode 7 GM on MacOSX 10.11 GM didn't work,
it results in:
errors > "no visible @ interface for 'CIImage' declares the selector 'size'" on lines 217, 229
warnings > Incompatible pointer types initializing 'UIImage *' with an expression of type 'CIImage * _Nullable"

any help?

Can you help me?

example : in this demo How Can I Use As the left is a picture and As the right is a title?
在这个demo里边我如何使用UImenuitem左边为图片,右边为文字的,并且可以扩展?请问有实现方法吗

Broken on iOS 13 (Beta 4)

The image is misplaced when calling initWithTitle:(NSString *)title action:(SEL)action image:(UIImage *)image on iOS 13 Beta 4. It's placed outside the UIMenuItem.

Menu in UITabBarController

I use this menu in view, which is in the UITabBarController. At the beginning menu works fine, but after switching tabs menu will no longer show up.

Crash with iOS 8.1: titleSettingsPairs is deallocated

Hello! I'm using HEAD of your library with the latest iOS SDK - I get the following error when trying to instantiate a menu item:

[__NSDictionaryM respondsToSelector:]: message sent to deallocated instance 0x7fc8a9d075d0

I haven't dug into this yet but it appears that the static titleSettingsPairs dictionary is at fault when storing the settings for a new item instance on line 71 of UIMenuItem+CXAImageSupport.m:

titleSettingsPairs[self.title] = settings;

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.