Skip to content

hbucius/DQAlertView

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DQAlertView

The best iOS customizable AlertView.

DQAlertView is the best alternative for UIKit's UIAlertView. With DQAlertView, you can easily make your desired Alert View in some lines of code.

.. .. ..

Getting started

Using CocoaPods

Just add the following line in to your pod file:

pod 'DQAlertView', '~> 1.1.1'

Manually

Drag and drop the subfolder named DQAlertView in your project and you are done.

What's new ?

v1.1.0: New feature: Customize alert by custom content view

Feature

With the DQAlertView, you can easily:

  • Customize alert appearance: custom frame, background color or background image, border corner, border radius
  • Customize title font, color, position
  • Customize message font, color, position
  • Customize buttons font, color, position
  • Customize separator color, hidden or not
  • Customize alert appear behaviour and disappear behaviour
  • Customize alert by custom content view
  • Callbacks and blocks for appearance or button touching event
  • And much more ...

Usage

Initilization

Set the title to nil to make the alert be no title. Remove button by set its title to nil

// Initialize same as UIAlertView
DQAlertView * alertView = [[DQAlertView alloc] initWithTitle:@"Title" message:@"Sample Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK"];

// or
DQAlertView * alertView = [[DQAlertView alloc] initWithTitle:@"Title" message:@"Sample Message" cancelButtonTitle:@"Cancel" otherButtonTitle:@"OK"];

Show and dismiss

// Show in specified view
// If the custom frame has not been set, the alert will be shown at the center of the view
- (void)showInView:(UIView *)view;

// Show in window
// Always show at center
- (void)show;

// Dismiss the alert
- (void)dismiss;

Button touching event handler

alertView.cancelButtonAction = ^{
    NSLog(@"Cancel Clicked");
};
alertView.otherButtonAction = ^{
    NSLog(@"OK Clicked");
};
    
//    // You can also use:
//    [alertView actionWithBlocksCancelButtonHandler:^{
//        NSLog(@"Cancel Clicked");
//    } otherButtonHandler:^{
//        NSLog(@"OK Clicked");
//    }];
    

If you don't want to use blocks, implement <DQAlertViewDelegate> and use delegate methods:

alertView.delegate = self;

- (void)willAppearAlertView:(DQAlertView *)alertView
{
    NSLog(@"Alert View Will Appear");
}

- (void)didAppearAlertView:(DQAlertView *)alertView
{
    NSLog(@"Alert View Did Appear");
}

- (void)cancelButtonClickedOnAlertView:(DQAlertView *)alertView {
    NSLog(@"Cancel Clicked");
}

- (void)otherButtonClickedOnAlertView:(DQAlertView *)alertView {
    NSLog(@"OK Clicked");
}

Customization

DQAlertView can be customized with the following properties:

/// Set the custom frame for the Alert View
@property (nonatomic, assign) CGRect customFrame; // Default is same as UIAlertView


// You can get buttons and labels for customizing their appearance
@property (nonatomic, strong) UIButton * cancelButton; // Default is in blue color and system font 16
@property (nonatomic, strong) UIButton * otherButton; // Default is in blue color and system font 16
@property (nonatomic, strong) UILabel * titleLabel; // Default is in black color and system bold font 16
@property (nonatomic, strong) UILabel * messageLabel; // Default is in gray color and system font 14


// Set the height of title and button; and the padding of elements. The message label height is calculated based on its text and font.
@property (nonatomic, assign) CGFloat buttonHeight; // Default is 44
@property (nonatomic, assign) CGFloat titleHeight; // Default is 30

@property (nonatomic, assign) CGFloat titleTopPadding; //Default is 5
@property (nonatomic, assign) CGFloat titleBottomPadding; // Default is 0
@property (nonatomic, assign) CGFloat messageBottomPadding; // Default is 10
@property (nonatomic, assign) CGFloat messageLeftRightPadding; // Default is 10


// Customize the background and border
@property (nonatomic, strong) UIColor * borderColor; // Default is no border
@property (nonatomic, assign) CGFloat borderWidth; // Default is 0
@property (nonatomic, assign) CGFloat cornerRadius; // Default is 4
// inherits from UIView @property (nonatomic, strong) UIColor * backgroundColor; // Default is white color with alpha 1
@property (nonatomic, strong) UIImage * backgroundImage; // Default is nil


// Customize the seperator
@property (nonatomic, assign) BOOL hideSeperator; // Default is NO
@property (nonatomic, strong) UIColor * seperatorColor; // Default is light gray color


// Customize the appearing and disappearing animations
@property (nonatomic, assign) DQAlertViewAnimationType appearAnimationType;
@property (nonatomic, assign) DQAlertViewAnimationType disappearAnimationType;
@property (nonatomic, assign) NSTimeInterval appearTime; // Default is 0.5
@property (nonatomic, assign) NSTimeInterval disappearTime; // Default is 0.3


// Make the cancel button appear on the right by setting this to YES
@property (nonatomic, assign) BOOL cancelButtonPositionRight; // Default is NO

// Disable the button highlight by setting this property to NO
@property (nonatomic, assign) BOOL buttonClickedHighlight; //Default is YES

// By default the alert will not dismiss if clicked to other button, set this property to YES to change the behaviour
@property (nonatomic, assign) BOOL shouldDismissOnActionButtonClicked; //Default is NO

// If this property is YES, the alert will dismiss when you click on outside (only when dim background is enable)
@property (nonatomic, assign) BOOL shouldDismissOnOutsideTapped; //Default is NO

// When shown in window, the dim background is always enable
@property (nonatomic, assign) BOOL shouldDimBackgroundWhenShowInWindow; //Default is YES

// When shown in view, the dim background is always disable
@property (nonatomic, assign) BOOL shouldDimBackgroundWhenShowInView; //Default is NO

// The default color of dim background is black color with alpha 0.2
@property (nonatomic, assign) CGFloat dimAlpha; //Default is 0.2

// Delegate
@property (nonatomic, strong) id<DQAlertViewDelegate> delegate;

// Handle the button touching event
@property (readwrite, copy) DQAlertViewBlock cancelButtonAction;
@property (readwrite, copy) DQAlertViewBlock otherButtonAction;

Contributing

Contributions for bug fixing or improvements are welcomed. Feel free to submit a pull request. If you have any questions, feature suggestions or bug reports, please send me an email to [email protected].

About

The best iOS customizable AlertView

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 93.5%
  • XML 5.0%
  • Ruby 1.5%