Code Monkey home page Code Monkey logo

popup's Introduction

Popup

• Screenshots and Gifs

SS1

SS2

SS3

• Installation

Just drag and drop the "Popup" folder into your project, and make sure you check the "Copy items into destination group's folder" box

- Then import Popup.h and set the PopupDelegate wherever you need it
#import "Popup.h"

@interface ViewController () <PopupDelegate>

• Creating Popups

- Creating a Basic Popup
Popup *popup = [[Popup alloc] initWithTitle:@"Title"
                                   subTitle:@"Subtitle"
                                cancelTitle:@"Cancel"
                               successTitle:@"Success"];
[popup setDelegate:self];
[popup showPopup];
- Creating a Popup with Blocks
Popup *popup = [[Popup alloc] initWithTitle:@"Title"
                                   subTitle:@"Subtitle"
                                cancelTitle:@"Cancel"
                               successTitle:@"Success"
                                cancelBlock:^{
                                //Custom code after cancel button was pressed
                                } successBlock:^{
                                //Custom code after success button was pressed
}];
[popup setDelegate:self];
[popup showPopup];
- Creating a Popup with Textfields

You can only add at most 3 textfields to Popup. Creating the textfields is as easy as creating an array with the placeholders you want your textfields to have: @[@"Placeholder1", @"Placeholder2", @"Placeholder3"] will create 3 textfields.

If you don't want a certain textfield to have a placeholder, you can leave the string blank: @[@"", @"Placeholder2"] will create 2 textfields, the first one with no placeholder text and the second textfield will have a placeholder of "Placeholder2".

The example below creates a Popup that has one textfield with a placeholder of "Username":

Popup *popup = [[Popup alloc] initWithTitle:@"Title"
                                   subTitle:@"Subtitle"
                      textFieldPlaceholders:@[@"Username"]
                                cancelTitle:@"Cancel"
                               successTitle:@"Success"
                                cancelBlock:^{
                                    //Custom code after cancel button was pressed
                                } successBlock:^{
                                    //Custom code after success button was pressed
}];
[popup setDelegate:self];
[popup showPopup];
- Caveats

You don't need to set anything in Popup if you don't want to. Just set nil values to the values that you don't want.

For example, if you don't want a cancel button, you can do the following:

Popup *popup = [[Popup alloc] initWithTitle:@"Title"
                                   subTitle:@"Subtitle"
                                cancelTitle:nil
                               successTitle:@"Success"];

• Setting Textfield Attributes

After creating a Popup with 1, 2 or 3 textfields, you can still manipulate each individual textfield to your liking.

- Secure entry

Popup has functions that allow you to set a certain textfield to secure. Popup textfields can either be of type @"PASSWORD" or @"DEFAULT" (they are set to @"DEFAULT" or @"" automatically).

The example below will set 3 textfields' entry types. The first and second textfield will have secure entry, and the last textfield will have default entry.

[popup setTextFieldTypeForTextFields:@[@"PASSWORD", @"PASSWORD", @"DEFAULT"]];
- Keyboard Types

You can set each individual textfield's UIKeyboardType by putting the type in an array and passing it through the popup. The types can be either @"DEFAULT", @"ASCIICAPABLE", @"NUMBERSANDPUNCTUATION", @"URL", @"NUMBER", @"PHONE", @"NAMEPHONE", @"EMAIL", @"DECIMAL", @"TWITTER", @"WEBSEARCH (they are set to @"DEFAULT", or @"" automatically).

The exmple below will set 3 textfields' UIKeyboardType by passing in the type as metioned above into an array. The first textfield will be set to UIKeyboardTypeDefault, the second textfield will be set to UIKeyboardTypeTwitter the third will be set to UIKeyboardTypeEmailAddress.

[popup setKeyboardTypeForTextFields:@"", @"TWITTER", @"EMAIL"];
- Keyboard Appearance

To set the overall UIKeyboardAppearance for all textfields in Popup, call one function on your existing Popup: The example below will set all keyboards to have a UIKeyboardAppearanceDark.

[popup setOverallKeyboardAppearance:UIKeyboardAppearanceDark];

• Setting Popup Visual Attributes

- Popup colors

You can pretty much set every color in Popup: Background, border color text labels, even button titles and button backgrounds.

[popup setBackgroundColor:[UIColor whiteColor]];
[popup setBorderColor:[UIColor blackColor]];
[popup setTitleColor:[UIColor darkTextColor]];
[popup setSubTitleColor:[UIColor lightTextColor]];
[popup setSuccessBtnColor:[UIColor blueColor]];
[popup setSuccessTitleColor:[UIColor whiteColor]];
[popup setCancelBtnColor:[UIColor redColor]];
[popup setCancelTitleColor:[UIColor whiteColor]];
- Background Blurs

Background blurs allow Popup to be viewed unobtrusively, disregarding the background content. Popup contains 4 background blur types: PopupBackGroundBlurTypeDark, PopupBackGroundBlurTypeLight, PopupBackGroundBlurTypeExtraLight, PopupBackGroundBlurTypeNone

[popup setBackgroundBlurType:PopupBackGroundBlurTypeDark];
- Popup Corners

You can set if your Popup has rounded corners or not.

[popup setRoundedCorners:YES];

• Setting Incoming and Outgoing Transitions

- Incoming Transitions

Popup has 10 incoming transition types that can be used to add an animation while presenting your Popup.

[popup setIncomingTransition:PopupIncomingTransitionTypeBounceFromCenter];
- Outgoing Transitions

Popup has 10 outgoing transition types that can be used to add an animation while dismissing your Popup.

[popup setOutgoingTransition:PopupOutgoingTransitionTypeBounceFromCenter];
- Tap To Dismiss

Tap the background of Popup to dismiss it. If you've already set a PopupOutgoingTransitionType it'll still trigger when you tap the background.
By tapping the background, you are dismissing Popup which is actually just cancelling it. This means that all delegate methods that return either a "Success" or a "Cancel" will return a "Cancel". This is automatically set to NO.

[popup setTapBackgroundToDismiss:YES];
- Swipe To Dismiss

Swipe Popup to dismiss it vertically (currently working on horizontally). If you've already set a PopupOutgoingTransitionType it will not trigger. By swiping Popup, you are dismissing Popup which is actually just cancelling it. This means that all delegate methods that return either a "Success" or a "Cancel" will return a "Cancel". This is automatically set to NO.

[popup setSwipeToDismiss:YES];

• Delegate Methods

- Appear and Disappear

Set Popup's delegate functions to tell when your Popup is appearing and which button the user pressed when dismissing.

- (void)popupWillAppear:(Popup *)popup;
- (void)popupDidAppear:(Popup *)popup;
- (void)popupWilldisappear:(Popup *)popup buttonType:(PopupButtonType)buttonType;
- (void)popupDidDisappear:(Popup *)popup buttonType:(PopupButtonType)buttonType;
- Button Callbacks
- (void)popupPressButton:(Popup *)popup buttonType:(PopupButtonType)buttonType {
    
    if (buttonType == PopupButtonCancel) {
        //Do whatever when the user taps the "Cancel" button
    }
    else if (buttonType == PopupButtonSuccess) {
        //Do whatever when the user taps the "Success" button
    }
    
}
- Retrieving Textfield Text

For all of the textfields in your Popup, it's easy to get the user's text input. The NSMutableDictionary returns the placeholders as the keys and the text from the textfields as the values. To get the strings from each individual textfields use the NSArray *stringArray to grab the object at a certain index:

- (void)dictionary:(NSMutableDictionary *)dictionary forpopup:(Popup *)popup stringsFromTextFields:(NSArray *)stringArray {
   
    NSString *textFromBox1 = [stringArray objectAtIndex:0];
    NSString *textFromBox2 = [stringArray objectAtIndex:1];
    NSString *textFromBox3 = [stringArray objectAtIndex:2];

}

• To-do

  • Swipe horizontally to dismiss

• Say Hi

Tweet at me or something : @markmiscavage.

• License

The MIT License (MIT)

Copyright (c) 2015 Mark Miscavage

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

popup's People

Contributors

miscavage avatar

Watchers

 avatar

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.