Coder Social home page Coder Social logo

qbpopupmenu's Introduction

QBPopupMenu

Customizable popup menu for iOS.

QBPopupMenu version 2.0 is now available.
Its appearance is similar to UIMenuController of iOS 7, and it has several new features.

Screenshot

screenshot01.png

screenshot02.png

Installation

QBPopupMenu is available in CocoaPods.

pod 'QBPopupMenu'

If you want to install manually, download this repository and copy files in QBPopupMenu directory to your project.

Feature

Customizable Appearance

QBPopupMenu is highly customizable, so you can create your own popup menu.

The simple way to customize is set color and highlightcolor property of QBPopupMenu.
If you want to customize deeply, you should create a subclass of QBPopupMenu and override some drawing methods.

QBPlasticPopupMenu class in this repository is a good example of subclassing.

Auto Pagenation

If you add many items to QBPopupMenu, it create pages and pagenator automatically.

Auto Bounding

QBPopupMenu automatically adjust its frame depending on the frame of target view.

Example

QBPopupMenuItem *item = [QBPopupMenuItem itemWithTitle:@"Text" target:self action:@selector(action:)];
QBPopupMenuItem *item2 = [QBPopupMenuItem itemWithImage:[UIImage imageNamed:@"image"] target:self action:@selector(action:)];

QBPopupMenu *popupMenu = [[QBPopupMenu alloc] initWithItems:@[item, item2]];

[popupMenu showInView:self.view targetRect:... animated:YES];

License

QBPopupMenu is released under the MIT License, see LICENSE.txt.

qbpopupmenu's People

Contributors

nek023 avatar podkovyrin 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  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

qbpopupmenu's Issues

Arrow direction

It'd be very nice if it was possible to toggle direction of arrow, for cases when the menu should appear below the button.

detecting touches outside the parent view

screen shot 2014-03-05 at 4 41 33 pm

In case anyone is interested, I was able to figure out how to use QBPopupMenu when it extends beyond the boundary of the parent view. In my case, it was for a UITextView positioned below a UITableView.

The important trick is that you need to have a common parent UIView that contains the view displaying the popup menu, as well as any views that it overlaps. The parent view needs to have access to the popup menu, so you'll need to allocate it there, or use a singleton. Then, override hitTest in the parentView:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    if ([_popupMenu isVisible]) {
        CGPoint localPoint = [self convertPoint:point toView:_popupMenu];
        UIView * view = [_popupMenu hitTest:localPoint withEvent:event];
        if (view)
            return view;
    }
    return [super hitTest:point withEvent:event];
}

There is no issue here, unless you want to add an example to the Demo. :)

Cocoapod

Your menu looks great but it would be much more helpful if you could provide it as an cocoapod.

Some improvements

1 - Arrow Direction Could help great if we show this control on top left corner.
2 - if the width exceeds from the width of parent view then it should show a more options automatically.

great control, really helps a lot

Trouble with targetRect and arrow height

I've been struggling with the location of my popup menus for a couple of hours. I want them to come up adjacent to the location of the user's finger, like in iMessages. In certain areas of my UITableView the QBPopupMenus insist on showing with the arrow facing the wrong direction, and the menu underlapping other controls. I fiddled a lot with targetRect's origin and size but couldn't figure out why things went wrong until I finally stepped through the code for showInView.

At first I thought that popupMenuInsets was responsible. With the default values of 10,10,10,10, there was a 10 px wide rectangle around my screen where the bubble would always come up wrong. But once I set the insets to 0, I STILL had a problem, and I think it is actually all due to a bug in showInView:

if (arrowDirection == QBPopupMenuArrowDirectionDefault) {
    if (targetRect.origin.y - ((self.height + self.arrowSize) - self.popupMenuInsets.top) >= 0) {
        arrowDirection = QBPopupMenuArrowDirectionDown;
    }
    else if (targetRect.origin.y + targetRect.size.height + (self.height + self.arrowSize) + self.popupMenuInsets.bottom < view.bounds.size.height) {
        arrowDirection = QBPopupMenuArrowDirectionUp;
    }
    else {
        CGFloat left = targetRect.origin.x - self.popupMenuInsets.left;
        CGFloat right = view.bounds.size.width - (targetRect.origin.x + targetRect.size.width + self.popupMenuInsets.right);

        arrowDirection = (left > right) ? QBPopupMenuArrowDirectionLeft : QBPopupMenuArrowDirectionRight;
    }
}

There are two places where (self.height + self.arrowDirection) should be (self.height + arrowSize).

But, there's still a problem with bubbles that get too close to the side of the screen, as in this screen shot. The targetRect is 300,200,1,1. Anything with an x origin greater than 292 exhibits the problem to some degree.

screen shot 2014-03-04 at 4 52 15 pm

I think the correct solution is to add two more cases to showInView that check the horizontal width of the targetRect + arrowSize.

And if you've read all the way to the end, thanks! And thanks for releasing this great component. I was in a real bind when I realized that UIMenuController's background color can't be set, and was nearly invisible on my black UITableView.

Menu button not clicking in Swift 3

I am using QBPopupMenu in Swift, but popmenu button are not clicked it's target method. here i am attaching my code.

class MenuViewController: UIViewController {

@IBOutlet weak var tapView : UIView!
var popUpMenu : QBPopupMenu!

override func viewDidLoad() {
    super.viewDidLoad()

    let menuItem = QBPopupMenuItem(title: "Split", target: self, action: #selector(splitProcess))
    let menuItemTwo : QBPopupMenuItem = QBPopupMenuItem(title: "Duplicate", target: self, action: #selector(MenuViewController.splitProcess))
    let menuItemThree : QBPopupMenuItem = QBPopupMenuItem(title: "Speed", target: self, action: #selector(MenuViewController.splitProcess))
    let menuItemFour : QBPopupMenuItem = QBPopupMenuItem(title: "Delete", target: self, action: #selector(MenuViewController.splitProcess))
    
    let items:Array = [menuItem,menuItemTwo,menuItemThree,menuItemFour]
    let popUpMenuFinal = QBPopupMenu(items: items)
    
    let tap = UITapGestureRecognizer(target: self, action: #selector(MenuViewController.split))
    tapView.addGestureRecognizer(tap)
    self.popUpMenu = popUpMenuFinal
}
func split(){
    print("Split Clicked")
    self.popUpMenu.showInView(tapView, targetRect: tapView.frame, animated: true)
}
func splitProcess(){
    print("Clicked")
}   

}

Blocks

Currently I didn't understand how to get to know whack item was tapped.
Completion block for an item is heavily needed.

no sender sent to button action

If the QBPopupMenuItem was the sender, a single action could handle multiple menu items. This is good when the menu items are generated programatically.

For example:

- (void)contextMenuItemSelected:(id)sender {
  QBPopupMenuItem *item = (QBPopupMenuItem*) sender;
  assert(item); // This currently fails.
  [self performCommandNamed: item.title];
}

This change is as simple as modifying -[QBPopupMenuItemView performAction]:

[self.item.target performSelector:self.item.action withObject:self.item afterDelay:0];

Menu overlay blocks UI

I store a menu in a property, When I show the menu and press a menu item many times my application hangs. I did a little research and found that popup's overlay is created in the method - (void)showInView:(UIView *)view targetRect:(CGRect)targetRect animated:(BOOL)animated;
So I think that for a some reason an overlay view is created several times and only one overlay is removed when use press a menu item.
Could you please fix this?

View of menu not showing properly in iPhone 6+

Hi,
I use a QBPlasticPopupmenu with 4 items, everything OK for iPhone 4,5,6 but when trying for iPhone 6+ the menu gets cut and the separators don´t appear where they should.... the last item gets cut and also do the arrow and bottom part of the menu. I use exactly the same code than your example.
Some idea?

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.