QMUIAlertController
@interface QMUIAlertController
: UIViewController <QMUIModalPresentationComponentProtocol> {
UIView *_containerView;
UIView *_scrollWrapView;
UIScrollView *_headerScrollView;
UIScrollView *_buttonScrollView;
UIControl *_maskView;
}
QMUIAlertController
是模仿系统UIAlertController
的控件,所以系统有的功能在QMUIAlertController里面基本都有。同时QMUIAlertController
还提供了一些扩展功能,例如:它的每个 button 都是开放出来的,可以对默认的按钮进行二次处理(比如加一个图片);可以通过 appearance 在 app 启动的时候修改整个QMUIAlertController
的主题样式。
-
Undocumented
Declaration
Objective-C
UIView *_containerView
-
Undocumented
Declaration
Objective-C
UIView *_scrollWrapView
-
Undocumented
Declaration
Objective-C
UIScrollView *_headerScrollView
-
Undocumented
Declaration
Objective-C
UIScrollView *_buttonScrollView
-
Undocumented
Declaration
Objective-C
UIControl *_maskView
-
alert距离屏幕四边的间距,默认UIEdgeInsetsMake(0, 0, 0, 0)。alert的宽度最终是通过屏幕宽度减去水平的 alertContentMargin 和 alertContentMaximumWidth 决定的。
Declaration
Objective-C
@property (nonatomic) UIEdgeInsets alertContentMargin;
Swift
var alertContentMargin: UIEdgeInsets { get set }
-
alert的最大宽度,默认270。
Declaration
Objective-C
@property (nonatomic) CGFloat alertContentMaximumWidth;
Swift
var alertContentMaximumWidth: CGFloat { get set }
-
alert上分隔线颜色,默认UIColorMake(211, 211, 219)。
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *alertSeparatorColor;
Swift
var alertSeparatorColor: UIColor? { get set }
-
alert标题样式,默认@{NSForegroundColorAttributeName:UIColorBlack,NSFontAttributeName:UIFontBoldMake(17),NSParagraphStyleAttributeName:[NSMutableParagraphStyle qmui_paragraphStyleWithLineHeight:0 lineBreakMode:NSLineBreakByTruncatingTail]}
Declaration
Objective-C
@property (nonatomic, strong, nullable) NSDictionary<NSAttributedStringKey, id> *alertTitleAttributes;
Swift
var alertTitleAttributes: [NSAttributedString.Key : Any]? { get set }
-
alert信息样式,默认@{NSForegroundColorAttributeName:UIColorBlack,NSFontAttributeName:UIFontMake(13),NSParagraphStyleAttributeName:[NSMutableParagraphStyle qmui_paragraphStyleWithLineHeight:0 lineBreakMode:NSLineBreakByTruncatingTail]}
Declaration
Objective-C
@property (nonatomic, strong, nullable) NSDictionary<NSAttributedStringKey, id> *alertMessageAttributes;
Swift
var alertMessageAttributes: [NSAttributedString.Key : Any]? { get set }
-
alert按钮样式,默认@{NSForegroundColorAttributeName:UIColorBlue,NSFontAttributeName:UIFontMake(17),NSKernAttributeName:@(0)}
Declaration
Objective-C
@property (nonatomic, strong, nullable) NSDictionary<NSAttributedStringKey, id> *alertButtonAttributes;
Swift
var alertButtonAttributes: [NSAttributedString.Key : Any]? { get set }
-
alert按钮disabled时的样式,默认@{NSForegroundColorAttributeName:UIColorMake(129, 129, 129),NSFontAttributeName:UIFontMake(17),NSKernAttributeName:@(0)}
Declaration
Objective-C
@property (nonatomic, strong, nullable) NSDictionary<NSAttributedStringKey, id> *alertButtonDisabledAttributes;
Swift
var alertButtonDisabledAttributes: [NSAttributedString.Key : Any]? { get set }
-
alert cancel 按钮样式,默认@{NSForegroundColorAttributeName:UIColorBlue,NSFontAttributeName:UIFontBoldMake(17),NSKernAttributeName:@(0)}
Declaration
Objective-C
@property (nonatomic, strong, nullable) NSDictionary<NSAttributedStringKey, id> *alertCancelButtonAttributes;
Swift
var alertCancelButtonAttributes: [NSAttributedString.Key : Any]? { get set }
-
alert destructive 按钮样式,默认@{NSForegroundColorAttributeName:UIColorRed,NSFontAttributeName:UIFontMake(17),NSKernAttributeName:@(0)}
Declaration
Objective-C
@property (nonatomic, strong, nullable) NSDictionary<NSAttributedStringKey, id> *alertDestructiveButtonAttributes;
Swift
var alertDestructiveButtonAttributes: [NSAttributedString.Key : Any]? { get set }
-
alert圆角大小,默认值是 13,以保持与系统默认样式一致
Declaration
Objective-C
@property (nonatomic) CGFloat alertContentCornerRadius;
Swift
var alertContentCornerRadius: CGFloat { get set }
-
alert按钮高度,默认44pt
Declaration
Objective-C
@property (nonatomic) CGFloat alertButtonHeight;
Swift
var alertButtonHeight: CGFloat { get set }
-
alert头部(非按钮部分)背景色,默认值是:UIColorMakeWithRGBA(247, 247, 247, 1)
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *alertHeaderBackgroundColor;
Swift
var alertHeaderBackgroundColor: UIColor? { get set }
-
alert按钮背景色,默认值同
alertHeaderBackgroundColor
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *alertButtonBackgroundColor;
Swift
var alertButtonBackgroundColor: UIColor? { get set }
-
alert按钮高亮背景色,默认UIColorMake(232, 232, 232)
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *alertButtonHighlightBackgroundColor;
Swift
var alertButtonHighlightBackgroundColor: UIColor? { get set }
-
alert头部四边insets间距
Declaration
Objective-C
@property (nonatomic) UIEdgeInsets alertHeaderInsets;
Swift
var alertHeaderInsets: UIEdgeInsets { get set }
-
alert头部title和message之间的间距,默认3pt
Declaration
Objective-C
@property (nonatomic) CGFloat alertTitleMessageSpacing;
Swift
var alertTitleMessageSpacing: CGFloat { get set }
-
alert 内部 textField 的字体
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIFont *alertTextFieldFont;
Swift
var alertTextFieldFont: UIFont? { get set }
-
alert 内部 textField 的文字颜色
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *alertTextFieldTextColor;
Swift
var alertTextFieldTextColor: UIColor? { get set }
-
alert 内部 textField 的边框颜色,如果不需要边框,可设置为 nil
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *alertTextFieldBorderColor;
Swift
var alertTextFieldBorderColor: UIColor? { get set }
-
sheet距离屏幕四边的间距,默认UIEdgeInsetsMake(10, 10, 10, 10)。
Declaration
Objective-C
@property (nonatomic) UIEdgeInsets sheetContentMargin;
Swift
var sheetContentMargin: UIEdgeInsets { get set }
-
sheet的最大宽度,默认值是5.5英寸的屏幕的宽度减去水平的 sheetContentMargin
Declaration
Objective-C
@property (nonatomic) CGFloat sheetContentMaximumWidth;
Swift
var sheetContentMaximumWidth: CGFloat { get set }
-
sheet分隔线颜色,默认UIColorMake(211, 211, 219)
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *sheetSeparatorColor;
Swift
var sheetSeparatorColor: UIColor? { get set }
-
sheet标题样式,默认@{NSForegroundColorAttributeName:UIColorMake(143, 143, 143),NSFontAttributeName:UIFontBoldMake(13),NSParagraphStyleAttributeName:[NSMutableParagraphStyle qmui_paragraphStyleWithLineHeight:0 lineBreakMode:NSLineBreakByTruncatingTail]}
Declaration
Objective-C
@property (nonatomic, copy, nullable) NSDictionary<NSAttributedStringKey, id> *sheetTitleAttributes;
Swift
var sheetTitleAttributes: [NSAttributedString.Key : Any]? { get set }
-
sheet信息样式,默认@{NSForegroundColorAttributeName:UIColorMake(143, 143, 143),NSFontAttributeName:UIFontMake(13),NSParagraphStyleAttributeName:[NSMutableParagraphStyle qmui_paragraphStyleWithLineHeight:0 lineBreakMode:NSLineBreakByTruncatingTail]}
Declaration
Objective-C
@property (nonatomic, copy, nullable) NSDictionary<NSAttributedStringKey, id> *sheetMessageAttributes;
Swift
var sheetMessageAttributes: [NSAttributedString.Key : Any]? { get set }
-
sheet按钮样式,默认@{NSForegroundColorAttributeName:UIColorBlue,NSFontAttributeName:UIFontMake(20),NSKernAttributeName:@(0)}
Declaration
Objective-C
@property (nonatomic, copy, nullable) NSDictionary<NSAttributedStringKey, id> *sheetButtonAttributes;
Swift
var sheetButtonAttributes: [NSAttributedString.Key : Any]? { get set }
-
sheet按钮disabled时的样式,默认@{NSForegroundColorAttributeName:UIColorMake(129, 129, 129),NSFontAttributeName:UIFontMake(20),NSKernAttributeName:@(0)}
Declaration
Objective-C
@property (nonatomic, copy, nullable) NSDictionary<NSAttributedStringKey, id> *sheetButtonDisabledAttributes;
Swift
var sheetButtonDisabledAttributes: [NSAttributedString.Key : Any]? { get set }
-
sheet cancel 按钮样式,默认@{NSForegroundColorAttributeName:UIColorBlue,NSFontAttributeName:UIFontBoldMake(20),NSKernAttributeName:@(0)}
Declaration
Objective-C
@property (nonatomic, copy, nullable) NSDictionary<NSAttributedStringKey, id> *sheetCancelButtonAttributes;
Swift
var sheetCancelButtonAttributes: [NSAttributedString.Key : Any]? { get set }
-
sheet destructive 按钮样式,默认@{NSForegroundColorAttributeName:UIColorRed,NSFontAttributeName:UIFontMake(20),NSKernAttributeName:@(0)}
Declaration
Objective-C
@property (nonatomic, copy, nullable) NSDictionary<NSAttributedStringKey, id> *sheetDestructiveButtonAttributes;
Swift
var sheetDestructiveButtonAttributes: [NSAttributedString.Key : Any]? { get set }
-
sheet cancel 按钮距离其上面元素(按钮或者header)的间距,默认8pt
Declaration
Objective-C
@property (nonatomic) CGFloat sheetCancelButtonMarginTop;
Swift
var sheetCancelButtonMarginTop: CGFloat { get set }
-
sheet内容的圆角,默认值是 13,以保持与系统默认样式一致
Declaration
Objective-C
@property (nonatomic) CGFloat sheetContentCornerRadius;
Swift
var sheetContentCornerRadius: CGFloat { get set }
-
sheet按钮高度,默认值是 57,以保持与系统默认样式一致
Declaration
Objective-C
@property (nonatomic) CGFloat sheetButtonHeight;
Swift
var sheetButtonHeight: CGFloat { get set }
-
sheet头部(非按钮部分)背景色,默认值是:UIColorMakeWithRGBA(247, 247, 247, 1)
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *sheetHeaderBackgroundColor;
Swift
var sheetHeaderBackgroundColor: UIColor? { get set }
-
sheet按钮背景色,默认值同
sheetHeaderBackgroundColor
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *sheetButtonBackgroundColor;
Swift
var sheetButtonBackgroundColor: UIColor? { get set }
-
sheet按钮高亮背景色,默认UIColorMake(232, 232, 232)
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *sheetButtonHighlightBackgroundColor;
Swift
var sheetButtonHighlightBackgroundColor: UIColor? { get set }
-
sheet头部四边insets间距
Declaration
Objective-C
@property (nonatomic) UIEdgeInsets sheetHeaderInsets;
Swift
var sheetHeaderInsets: UIEdgeInsets { get set }
-
sheet头部title和message之间的间距,默认8pt
Declaration
Objective-C
@property (nonatomic) CGFloat sheetTitleMessageSpacing;
Swift
var sheetTitleMessageSpacing: CGFloat { get set }
-
sheet 的列数,一行显示多少个 button,默认是 1。
Declaration
Objective-C
@property (nonatomic) CGFloat sheetButtonColumnCount;
Swift
var sheetButtonColumnCount: CGFloat { get set }
-
默认初始化方法
Declaration
Objective-C
- (nonnull instancetype)initWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(QMUIAlertControllerStyle)preferredStyle;
Swift
init(title: String?, message: String?, preferredStyle: QMUIAlertControllerStyle)
-
通过类方法初始化实例
Declaration
Objective-C
+ (nonnull instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle: (QMUIAlertControllerStyle)preferredStyle;
-
Declaration
Objective-C
@property (nonatomic, weak, nullable) id<QMUIAlertControllerDelegate> delegate;
Swift
weak var delegate: QMUIAlertControllerDelegate? { get set }
-
增加一个按钮
Declaration
Objective-C
- (void)addAction:(nonnull QMUIAlertAction *)action;
Swift
func addAction(_ action: QMUIAlertAction)
-
Undocumented
Declaration
Objective-C
- (void)addCancelAction;
Swift
func addCancelAction()
-
增加一个输入框
Declaration
Objective-C
- (void)addTextFieldWithConfigurationHandler: (void (^_Nullable)(QMUITextField *_Nonnull))configurationHandler;
Swift
func addTextField(configurationHandler: ((QMUITextField) -> Void)? = nil)
-
是否应该自动管理输入框的键盘 Return 事件(切换多个输入框的焦点、自动响应某个按钮等),默认为 YES。你也可以通过 UITextFieldDelegate 自己管理,此时请将此属性置为 NO。
Declaration
Objective-C
@property (nonatomic) BOOL shouldManageTextFieldsReturnEventAutomatically;
Swift
var shouldManageTextFieldsReturnEventAutomatically: Bool { get set }
-
增加一个自定义的view作为
QMUIAlertController
的customViewDeclaration
Objective-C
- (void)addCustomView:(UIView *_Nullable)view;
Swift
func addCustomView(_ view: UIView?)
-
显示
QMUIAlertController
Declaration
Objective-C
- (void)showWithAnimated:(BOOL)animated;
Swift
func showWith(animated: Bool)
-
隐藏
QMUIAlertController
Declaration
Objective-C
- (void)hideWithAnimated:(BOOL)animated;
Swift
func hideWith(animated: Bool)
-
所有
QMUIAlertAction
对象Declaration
Objective-C
@property (nonatomic, copy, readonly, nullable) NSArray<QMUIAlertAction *> *actions;
Swift
var actions: [QMUIAlertAction]? { get }
-
当前所有通过
addTextFieldWithConfigurationHandler:
接口添加的输入框Declaration
Objective-C
@property (nonatomic, copy, readonly, nullable) NSArray<QMUITextField *> *textFields;
Swift
var textFields: [QMUITextField]? { get }
-
设置自定义view。通过
addCustomView:
方法添加一个自定义的view,QMUIAlertController
会在布局的时候去调用这个view的sizeThatFits:
方法来获取size,至于x和y坐标则由控件自己控制。Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) UIView *customView;
Swift
var customView: UIView? { get }
-
当前标题title
Declaration
Objective-C
@property (nonatomic, copy, nullable) NSString *title;
Swift
var title: String? { get set }
-
当前信息message
Declaration
Objective-C
@property (nonatomic, copy, nullable) NSString *message;
Swift
var message: String? { get set }
-
当前样式style
Declaration
Objective-C
@property (nonatomic, readonly) QMUIAlertControllerStyle preferredStyle;
Swift
var preferredStyle: QMUIAlertControllerStyle { get }
-
将
QMUIAlertController
弹出来的QMUIModalPresentationViewController
对象Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) QMUIModalPresentationViewController *modalPresentationViewController;
Swift
var modalPresentationViewController: QMUIModalPresentationViewController? { get }
-
主体内容(alert 下指整个弹窗,actionSheet 下指取消按钮上方的那些 header 和 按钮)背后用来做背景样式的 view,默认为空白的 UIView,当你需要做磨砂效果时可以将一个 UIVisualEffectView 赋值给它(但推荐用 QMUIVisualEffectView)。当赋值为 nil 时,内部会自动创建一个空白的 UIView 代替,以保证这个属性不为空。
Declaration
Objective-C
@property (nonatomic, strong, null_resettable) UIView *mainVisualEffectView;
Swift
var mainVisualEffectView: UIView! { get set }
-
actionSheet 下的取消按钮背后用来做背景样式的 view,默认为空白的 UIView,当你需要做磨砂效果时可以将一个 UIVisualEffectView 赋值给它(但推荐用 QMUIVisualEffectView)。alert 情况下不会出现。当赋值为 nil 时,内部会自动创建一个空白的 UIView 代替,以保证这个属性不为空。
Declaration
Objective-C
@property (nonatomic, strong, null_resettable) UIView *cancelButtonVisualEffectView;
Swift
var cancelButtonVisualEffectView: UIView! { get set }
-
设置按钮的排序是否要由用户添加的顺序来决定,默认为NO,也即与系统原生
UIAlertController
一致,QMUIAlertActionStyleDestructive 类型的action必定在最后面。Warning
注意 QMUIAlertActionStyleCancel 按钮不受这个属性的影响Declaration
Objective-C
@property (nonatomic) BOOL orderActionsByAddedOrdered;
Swift
var orderActionsByAddedOrdered: Bool { get set }
-
maskView是否响应点击,alert默认为NO,sheet默认为YES
Declaration
Objective-C
@property (nonatomic) BOOL shouldRespondMaskViewTouch;
Swift
var shouldRespondMaskViewTouch: Bool { get set }
-
在 iPhoneX 机器上是否延伸底部背景色。因为在 iPhoneX 上我们会把整个面板往上移动 safeArea 的距离,如果你的面板本来就配置成撑满全屏的样式,那么就会露出底部的空隙,isExtendBottomLayout 可以帮助你把空暇填补上。默认为NO。 @warning: 只对 sheet 类型有效
Declaration
Objective-C
@property (nonatomic) BOOL isExtendBottomLayout;
Swift
var isExtendBottomLayout: Bool { get set }
-
在显示 alert 之前先降下键盘,默认为 YES。系统的 UIAlertController 也会在显示时降下键盘,但它能在消失后把键盘自动升起,并且这个过程不会触发 becomeFirstResponder/resignFirstResponder,QMUIAlertController 暂时做不到这样的效果,只负责降下,不负责恢复。 iOS 10 及以上,一个 UIWindow 显示出来时默认就会降下键盘,所以这个属性只在 iOS 9 里有效,iOS 10 及以上即便设置为 NO 也没有效果。
Declaration
Objective-C
@property (nonatomic) BOOL dismissKeyboardAutomatically;
Swift
var dismissKeyboardAutomatically: Bool { get set }
-
Undocumented
Declaration
Objective-C
+ (instancetype)appearance;
Swift
class func appearance() -> Self
-
可方便地判断是否有 alertController 正在显示,全局生效
Declaration
Objective-C
+ (BOOL)isAnyAlertControllerVisible;
Swift
class func isAnyAlertControllerVisible() -> Bool