Giter Site home page Giter Site logo

arspopover's Introduction

ARSPopover GitHub license

Universal popover for iPhone and iPad that you can use in your projects. No custom drawing, no custom elements - everything is purely native.

iPhone iPad
ARSPopover-iPhone ARSPopover-iPad

Installation

CocoaPods

To install with CocoaPods, copy and paste this in your Podfile file:

platform :ios, '8.3'
pod 'ARSPopover', '~> 2.0'

Non-CocoaPods way

You can always to do the old way - just drag the source files into your projects and you are good to go.

Usage

Sample usage of the ARSPopover might look like this:

- (IBAction)showPopoverWithWebView:(id)sender {
    ARSPopover *popoverController = [ARSPopover new];
    popoverController.sourceView = self.buttonWithWebView;
    popoverController.sourceRect = CGRectMake(CGRectGetMidX(self.buttonWithWebView.bounds), CGRectGetMaxY(self.buttonWithWebView.bounds), 0, 0);
    popoverController.contentSize = CGSizeMake(400, 600);
    popoverController.arrowDirection = UIPopoverArrowDirectionUp;

    [self presentViewController:popoverController animated:YES completion:^{
        [popoverController insertContentIntoPopover:^(ARSPopover *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
            CGFloat originX = 0;
            CGFloat originY = 0;
            CGFloat width = popoverPresentedSize.width;
            CGFloat height = popoverPresentedSize.height - popoverArrowHeight;

            CGRect frame = CGRectMake(originX, originY, width, height);
            UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
            webView.scalesPageToFit = YES;
            [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://google.com"]]];
            [popover.view addSubview:webView];
        }];
    }];
}

Required properties' configurations

In order to get a working popover, you need to specify next properties:

  • popoverController.sourceView - The view containing the anchor rectangle for the popover.
popoverController.sourceView = self.buttonWithWebView;
  • popoverController.sourceRect - The rectangle in the specified view in which to anchor the popover.
popoverController.sourceRect = CGRectMake(CGRectGetMidX(self.buttonWithWebView.bounds), CGRectGetMaxY(self.buttonWithWebView.bounds), 0, 0);
  • popoverController.contentSize - The preferred size for the popover’s view.
popoverController.contentSize = CGSizeMake(400, 600);
  • And the last, most important thing - you have to call method insertContentIntoPopover and pass a block of code, which should add subviews to popover's view you wish to see.

Be sure to call this method only after you have presented popup. Otherwise you might get wrong size in popoverPresentedSize.

[popoverController insertContentIntoPopover:^(ARSPopover *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
    CGFloat originX = 0;
    CGFloat originY = 0;
    CGFloat width = popoverPresentedSize.width;
    CGFloat height = popoverPresentedSize.height - popoverArrowHeight;

    CGRect frame = CGRectMake(originX, originY, width, height);
    UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
    webView.scalesPageToFit = YES;
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://google.com"]]];
    [popover.view addSubview:webView];
}];

Optional delegate methods

You can conform to ARSPopoverDelegate protocol, so that you could receive delegate calls from UIPopoverPresentationController. You can implement following delegate methods:

- (void)popoverPresentationController:(UIPopoverPresentationController *)popoverPresentationController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView *__autoreleasing *)view;
- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;
- (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;

License

ARSPopover is released under the MIT license. See LICENSE for details.

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.