Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cxa/UIMenuItem-CXAImageSupport
[Deprecated! Use MenuItemKit instead] UIMenuItem with Image Support
https://github.com/cxa/UIMenuItem-CXAImageSupport
Last synced: 3 months ago
JSON representation
[Deprecated! Use MenuItemKit instead] UIMenuItem with Image Support
- Host: GitHub
- URL: https://github.com/cxa/UIMenuItem-CXAImageSupport
- Owner: cxa
- License: mit
- Created: 2013-01-02T18:30:24.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2016-06-08T05:24:32.000Z (over 8 years ago)
- Last Synced: 2024-10-28T12:55:14.859Z (3 months ago)
- Language: Objective-C
- Homepage:
- Size: 473 KB
- Stars: 335
- Watchers: 22
- Forks: 36
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - UIMenuItem-CXAImageSupport - [Deprecated! Use MenuItemKit instead] UIMenuItem with Image Support (etc)
- awesome - UIMenuItem-CXAImageSupport - [Deprecated! Use MenuItemKit instead] UIMenuItem with Image Support (etc)
README
# UIMenuItem with Image Support
*Officially Deprecated! use [MenuItemKit](https://github.com/cxa/MenuItemKit) instead.*
![screenshot of UIMenuItem with image](screenshot.jpg)
`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+ (instancetype)settingsWithDictionary:(NSDictionary *)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](https://twitter.com/_cxa)
* Apps available in App Store:
* 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.