DQAlertView 1.3.0

DQAlertView 1.3.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布日期最后发布2020 年 8 月

Quan Dinh 维护。



  • 作者
  • Dinh Quan

DQAlertView

用 Swift 进行编程?尝试使用 SwiftAlertView 获取更传统的一组 API。

最佳 iOS 可定制 AlertView。

DQAlertView 是 UIKit 的 UIAlertView 的最佳替代品。使用 DQAlertView,您可以轻松地在几行代码中制作出您想要的 Alert View。

.. .. ..

入门

使用 CocoaPods

只需在 podfile 中添加以下行

pod 'DQAlertView', '~> 1.3.0'

手动处理

将名为 DQAlertView 的子文件夹拖放到项目中即可。

有什么新功能?

  • v1.1.0: 新功能:通过自定义内容视图定制警报
  • v1.2.0: DQAlertView 的默认外观与 UIAlertView 完全相同
  • v1.3.0: 支持长标题

功能

使用 DQAlertView,您可以轻松实现以下功能

  • 自定义警报外观:自定义边框、背景颜色或背景图片、边角、边框半径
  • 自定义标题字体、颜色、位置
  • 自定义消息字体、颜色、位置
  • 自定义按钮字体、颜色、位置
  • 自定义分隔符颜色,隐藏或显示
  • 自定义警报出现行为和消失行为
  • 通过自定义内容视图自定义警报
  • 外观或按钮触摸事件的自定义回调和块
  • 等等...

用法

初始化

将标题设置为 nil 使警报无标题。通过将其标题设置为 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 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;

按钮触摸事件处理器

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

如果您不想使用块,请实现 <DQAlertViewDelegate> 并使用代理方法

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");
}

定制

DQAlertView 可以通过以下属性进行定制

// Set the custom frame for the Alert View, if this property has not been set the Alert will be shown at center of the view. Don't use the default method [UIView setFrame:]
@property (nonatomic, assign) CGRect customFrame; // Default is same as UIAlertView


// Set the content view for the Alert View
// The frame of alert view will be resized based on the frame of content view, so you don't have to set the custom frame. If you want the alert view not shown at center, just set the center of the Alert View
@property (nonatomic, strong) UIView *contentView;


// 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 34

@property (nonatomic, assign) CGFloat titleTopPadding; //Default is 14
@property (nonatomic, assign) CGFloat titleBottomPadding; // Default is 2
@property (nonatomic, assign) CGFloat messageBottomPadding; // Default is 20
@property (nonatomic, assign) CGFloat messageLeftRightPadding; // Default is 20


// 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 8
// inherits from UIView @property (nonatomic, strong) UIColor * backgroundColor; // Default is same as UIAlertView
@property (nonatomic, strong) UIImage * backgroundImage; // Default is nil


// Customize the seperator
@property (nonatomic, assign) BOOL hideSeperator; // Default is NO
@property (nonatomic, strong) UIColor * separatorColor; // Default is same as UIAlertView


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


// 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 YES

// 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 same as UIAlertView

贡献

欢迎为错误修复或改进做出贡献。请随时提交拉取请求。如果您有任何问题、功能建议或错误报告,请通过电子邮件联系我 [email protected]