• Stars
    star
    179
  • Rank 214,039 (Top 5 %)
  • Language
    Objective-C
  • License
    Other
  • Created over 12 years ago
  • Updated over 9 years ago

Reviews

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

Repository Details

A block based UIMenuItem subclass.

PSMenuItem

A block based UIMenuItem subclass.

The inflexible @selector based approach in UIMenuItem was driving me crazy. I searched quite a while for a block-based UIMenuItem, but couldn't find one. So finally, I sat down and wrote my own implementation for my iOS PDF framework PSPDFKit.

If you are as annoyed about the missing target/action pattern, as I am, you will love this. Also read the in-depth article on my website.

How to use

    // one time-call needed to prepare the block based PSMenuItem handler.
    [PSMenuItem installMenuHandlerForObject:button];

    PSMenuItem *actionItem = [[PSMenuItem alloc] initWithTitle:@"Action 1" block:^{
        [[[UIAlertView alloc] initWithTitle:@"Message" message:@"From a block!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
    }];

    PSMenuItem *submenuItem = [[PSMenuItem alloc] initWithTitle:@"Submenu..." block:^{
        [UIMenuController sharedMenuController].menuItems = @[
        [[PSMenuItem alloc] initWithTitle:@"Back..." block:^{
            [self buttonPressed:button];
        }],
        [[PSMenuItem alloc] initWithTitle:@"Sub 1" block:^{
            NSLog(@"Sub 1 pressed");
        }]];
        [[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
    }];

    [UIMenuController sharedMenuController].menuItems = @[actionItem, submenuItem];
    [[UIMenuController sharedMenuController] setTargetRect:button.bounds inView:button];
    [[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];

PSMenuItem uses ARC and is tested with Xcode 4.4 and 4.5 (iOS 4.3+)

The code looks a bit scary and involves swizzling certain methods, but it's actually not that bad. No private API is used, and it's highly unlikely that Apple ever changes something as basic as the UIResponder chain.

Creator

Peter Steinberger @steipete

I'd love a thank you tweet if you find this useful.

License

PSMenuItem is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

Aspects

Delightful, simple library for aspect oriented programming in Objective-C and Swift.
Objective-C
8,383
star
2

PSTCollectionView

Open Source, 100% API compatible replacement of UICollectionView for iOS4.3+
Objective-C
2,546
star
3

PSStackedView

open source implementation of Twitter/iPad stacked ui - done right.
Objective-C
1,970
star
4

AFDownloadRequestOperation

A progressive download operation for AFNetworking.
Objective-C
1,051
star
5

InterposeKit

A modern library to swizzle elegantly in Swift.
Swift
962
star
6

PSPDFTextView

A subclass of UITextView that fixes the most glaring problems from iOS 7 and 7.1.
Objective-C
877
star
7

PSTAlertController

API similar to UIAlertController, backwards compatible to iOS 7. Will use the new shiny API when you run iOS 8.
Objective-C
737
star
8

PSPushPopPressView

Zoom, Rotate, Drag โ€“ everything at the same time. A view-container for direct manipulation, inspired by Our Choice from Push Pop Press.
Objective-C
611
star
9

PSFoundation

Categories and helper classes for iOS projects.
Objective-C
569
star
10

PSTDelegateProxy

A simple proxy that forwards optional methods to delegates - less boilerplate in your code!
Objective-C
256
star
11

PSYouTubeExtractor

Display YouTube URLs in a MPMoviePlayerController
Objective-C
191
star
12

UIKitDebugging

A set of files that enables various debug flags in UIKit
Objective-C
178
star
13

PSPDFKit-Demo

A drop-in-ready framework that helps in almost every aspect of PDF-rendering on iOS.
Objective-C
178
star
14

PSiOSAppTemplate

iOS Application Template with JSON-Parsing, AutoUpdating, CrashReporter+Sender, Statistics, custom Logging, Localization and all those little things already set up, ready for you to make awesome stuff!
Objective-C
174
star
15

PSAlertView

Modern block-based wrappers for UIAlertView and UIActionSheet.
Objective-C
129
star
16

PSStoreButton

UIButton that is styled like iPhone's AppStore-Button. No Images used!
Objective-C
91
star
17

PSTCenteredScrollView

Shows off different ways to center content in a UIScrollView.
Objective-C
79
star
18

NSLogger-CocoaLumberjack-connector

65
star
19

xcode-theme-solarized-modded

Heavily modded theme based on the Solarized style: http://ethanschoonover.com/solarized/
49
star
20

iOS6-Runtime-Headers

6.0 (GM)
Objective-C
47
star
21

speaking

Upcoming and past speaking engagements for Peter Steinberger (@steipete).
47
star
22

OSLogTest

Test app for OSLog
Swift
45
star
23

PSBackgroundCurtain

Fades the App to black/semi-black when in Background. Fully animated.
44
star
24

PSTFoundationBenchmark

Foundation Collection Classes Benchmarks
Objective-C
37
star
25

SwiftUITouchHandling

Testing touch handling from embedded SwiftUI views
Swift
28
star
26

stackoverflowerizer

always redirect to stackoverflow from pages that just copy the content, like efreedom
JavaScript
15
star
27

steipete.com

Personal Website of Peter Steinberger.
SCSS
13
star
28

dotfiles

my dot files for bash, git, rails and co
Shell
4
star