• Stars
    star
    338
  • Rank 124,899 (Top 3 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 12 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[Deprecated! Use MenuItemKit instead] UIMenuItem with Image Support

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.

More Repositories

1

MenuItemKit

UIMenuItem with image and closure(block) action
Swift
848
star
2

ppx_bsx

OCaml JSX for ReasonReact
OCaml
70
star
3

CXAHyperlinkLabel

A drop-in and easy-to-use replacement for UILabel for iOS 6, supports handling link click and long press with block.
Objective-C
51
star
4

KissNSUserDefaults

Keep NSUserDefaults simple, stupid. Access NSUserDefaults key using property, without subclassing.
Objective-C
46
star
5

CXAAutoRemovalNotification

[DEPRECATED] Less boilerplate code for NSNotificationCenter.
Objective-C
32
star
6

CXADirectoryContentsWatcher

Watch for a directory whenever a file is added or removed
Objective-C
30
star
7

DOMContentLoadedDelegate

Access `UIWebView` DOM asap
Swift
28
star
8

WebViewContentPositioner

Scroll position maintainer for UIWebView.
Swift
26
star
9

Mvce

An event driven MVC library to glue decoupled Model, View, and Controller for UIKit/AppKit. Minimal, simple, and unobtrusive.
Swift
23
star
10

Piz

The simplest unzipper just works. (Swift)
Swift
22
star
11

Fpub

Library for reading EPUB file format built on top of .NET Standard 2.0 and F#.
F#
19
star
12

Mu

Apply The Elm Architecture pattern on Xamarin stack, with another simple, unobtrusive way
F#
16
star
13

bs-containers-core

OCaml-containers core for BuckleScript.
OCaml
12
star
14

AppExtensionCommunicator

Communicate between app extension and its containing app. Swift framework.
Swift
12
star
15

NonConsumableIAPHelper

An extra lightweight wrapper for non-consumable In-App Purchase.
Objective-C
10
star
16

reason-react-webpack-starter-kit

JavaScript
9
star
17

ppx_bsx_example

JavaScript
7
star
18

XPaver

Make XML navigation by XPath easier
Swift
7
star
19

JsonR

OCaml
7
star
20

cxa.github.com

Personal page
HTML
6
star
21

HalfTea

Inspired by TEA (The Elm Architecture) but for Xamarin stack, in an unobstrusive way.
F#
5
star
22

vscode-elmx

elmx for Visual Studio Code
4
star
23

bs-websockets

OCaml
4
star
24

HaodooPDB

Extract contents from the PDB format of http://haodoo.net
Objective-C
3
star
25

bs-json-keypather

Navigate JSON with keypath for BuckleScript
OCaml
3
star
26

dicsrv

HTTP service for macOS Dictionary.app.
JavaScript
2
star
27

KissNSUbiquitousKeyValueStore

Keep NSUbiquitousKeyValueStore simple, stupid. Access NSUbiquitousKeyValueStore key using property, without subclassing.
Objective-C
1
star
28

dicmd

Command line for macOS Dictionary.app
C
1
star
29

chatgpt

ChatGPT in your terminal.
Shell
1
star
30

KeyPathJson

Safe and key-path-able JSON navigator for System.Json
F#
1
star
31

.emacs.d

Relocatable Emacs conf
Emacs Lisp
1
star