             headerScrollView.backgroundColor = alertHeaderBackgroundColor
         }
     }
-    
+
     private func updateEffectBackgroundColor() {
         if preferredStyle == .alert {
             headerEffectView.backgroundColor = alertSeperatorColor

 *  `QMUIAlertController`是模仿系统`UIAlertController`的控件，所以系统有的功能在QMUIAlertController里面基本都有。同时`QMUIAlertController`还提供了一些扩展功能，例如：它的每个 button 都是开放出来的，可以对默认的按钮进行二次处理（比如加一个图片）；可以通过 QMUIAlertController.appearance() 在 app 启动的时候修改整个`QMUIAlertController`的主题样式。
 */
class QMUIAlertController: UIViewController {
    
    /// alert距离屏幕四边的间距，默认UIEdgeInsetsMake(0, 0, 0, 0)。alert的宽度最终是通过屏幕宽度减去水平的 alertContentMargin 和 alertContentMaximumWidth 决定的。
    @objc dynamic public var alertContentMargin: UIEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
    
    /// alert的最大宽度，默认270。
    @objc dynamic public var alertContentMaximumWidth: CGFloat = 270
    
    /// alert上分隔线颜色，默认 UIColor(r: 211, g: 211, b: 219)。
    @objc dynamic public var alertSeperatorColor: UIColor = UIColor(r: 211, g: 211, b: 219) {
        didSet {
            updateEffectBackgroundColor()
        }
    }
    
    /// alert标题样式，默认 [NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font: UIFontBoldMake(17), NSAttributedStringKey.paragraphStyle: NSMutableParagraphStyle(lineHeight: 0, lineBreakMode: .byTruncatingTail)]
    @objc dynamic public var alertTitleAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font: UIFontBoldMake(17), NSAttributedStringKey.paragraphStyle: NSMutableParagraphStyle(lineHeight: 0, lineBreakMode: .byTruncatingTail)] {
        didSet {
            _needsUpdateTitle = true
        }
    }
    
    /// alert信息样式，默认 [NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font: UIFontMake(13), NSAttributedStringKey.paragraphStyle: NSMutableParagraphStyle(lineHeight: 0, lineBreakMode: .byTruncatingTail)]
    @objc dynamic public var alertMessageAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font: UIFontMake(13), NSAttributedStringKey.paragraphStyle: NSMutableParagraphStyle(lineHeight: 0, lineBreakMode: .byTruncatingTail)] {
        didSet {
            _needsUpdateMessage = true
        }
    }
    
    /// alert按钮样式，默认 [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFontMake(17), NSAttributedStringKey.kern: 0]
    @objc dynamic public var alertButtonAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFontMake(17), NSAttributedStringKey.kern: 0 as AnyObject] {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// alert按钮disabled时的样式，默认 [NSAttributedStringKey.foregroundColor: UIColor(r: 129, g: 129, b: 129), NSAttributedStringKey.font: UIFontMake(17), NSAttributedStringKey.kern: 0 as AnyObject]
    @objc dynamic public var alertButtonDisabledAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor(r: 129, g: 129, b: 129), NSAttributedStringKey.font: UIFontMake(17), NSAttributedStringKey.kern: 0 as AnyObject] {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// alert cancel 按钮样式，默认 [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFontBoldMake(17), NSAttributedStringKey.kern: 0 as AnyObject]
    @objc dynamic public var alertCancelButtonAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFontBoldMake(17), NSAttributedStringKey.kern: 0 as AnyObject] {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// alert destructive 按钮样式，默认 [NSAttributedStringKey.foregroundColor: UIColor.red, NSAttributedStringKey.font: UIFontMake(17), NSAttributedStringKey.kern: 0 as AnyObject]
    @objc dynamic public var alertDestructiveButtonAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor.red, NSAttributedStringKey.font: UIFontMake(17), NSAttributedStringKey.kern: 0 as AnyObject] {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// alert圆角大小，默认值是：IOS_VERSION >= 9.0 ? 13 : 6，以保持与系统默认样式一致
    @objc dynamic public var alertContentCornerRadius: CGFloat = (IOS_VERSION > 9.0 ? 13 : 6) {
        didSet {
            updateCornerRadius()
        }
    }
    
    /// alert按钮高度，默认44pt
    @objc dynamic public var alertButtonHeight: CGFloat = 44
    
    /// alert头部（非按钮部分）背景色，默认值是：UIColor(r: 247, g: 247, b: 247, a:1)
    @objc dynamic public var alertHeaderBackgroundColor: UIColor = UIColor(r: 247, g: 247, b: 247, a:1) {
        didSet {
            updateHeaderBackgrondColor()
        }
    }
    
    /// alert按钮背景色，默认值同`alertHeaderBackgroundColor`
    @objc dynamic public var alertButtonBackgroundColor: UIColor = UIColor(r: 247, g: 247, b: 247, a:1) {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// alert按钮高亮背景色，默认 UIColor(r: 232, g: 232, b: 232)
    @objc dynamic public var alertButtonHighlightBackgroundColor: UIColor = UIColor(r: 232, g: 232, b: 232) {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// alert头部四边insets间距
    @objc dynamic public var alertHeaderInsets: UIEdgeInsets = UIEdgeInsetsMake(20, 16, 20, 16)
    
    /// alert头部title和message之间的间距，默认3pt
    @objc dynamic public var alertTitleMessageSpacing: CGFloat = 3
    
    /// sheet距离屏幕四边的间距，默认UIEdgeInsetsMake(10, 10, 10, 10)。
    @objc dynamic public var sheetContentMargin: UIEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10)
    
    /// sheet的最大宽度，默认值是5.5英寸的屏幕的宽度减去水平的 sheetContentMargin
    @objc dynamic public var sheetContentMaximumWidth: CGFloat = QMUIHelper.screenSizeFor55Inch.width - UIEdgeInsetsMake(10, 10, 10, 10).horizontalValue
    
    /// sheet分隔线颜色，默认 UIColor(r: 211, g: 211, b: 219)
    @objc dynamic public var sheetSeperatorColor: UIColor = UIColor(r: 211, g: 211, b: 219) {
        didSet {
            updateEffectBackgroundColor()
        }
    }
    
    /// sheet标题样式，默认 [NSAttributedStringKey.foregroundColor: UIColor(r: 143, g: 143, b: 143), NSAttributedStringKey.font: UIFontBoldMake(13), NSAttributedStringKey.paragraphStyle: NSMutableParagraphStyle(lineHeight: 0, lineBreakMode: .byTruncatingTail)]
    @objc dynamic public var sheetTitleAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor(r: 143, g: 143, b: 143), NSAttributedStringKey.font: UIFontBoldMake(13), NSAttributedStringKey.paragraphStyle: NSMutableParagraphStyle(lineHeight: 0, lineBreakMode: .byTruncatingTail)] {
        didSet {
            _needsUpdateTitle = true
        }
    }
    
    /// sheet信息样式，默认 [NSAttributedStringKey.foregroundColor: UIColor(r: 143, g: 143, b: 143), NSAttributedStringKey.font: UIFontMake(13), NSAttributedStringKey.paragraphStyle: NSMutableParagraphStyle(lineHeight: 0, lineBreakMode: .byTruncatingTail)]
    @objc dynamic public var sheetMessageAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor(r: 143, g: 143, b: 143), NSAttributedStringKey.font: UIFontMake(13), NSAttributedStringKey.paragraphStyle: NSMutableParagraphStyle(lineHeight: 0, lineBreakMode: .byTruncatingTail)] {
        didSet {
            _needsUpdateMessage = true
        }
    }
    
    /// sheet按钮样式，默认 [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFontMake(20), NSAttributedStringKey.kern: 0 as AnyObject]
    @objc dynamic public var sheetButtonAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFontMake(20), NSAttributedStringKey.kern: 0 as AnyObject] {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// sheet按钮disabled时的样式，默认 [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor(r: 129, g: 129, b: 129), NSAttributedStringKey.font: UIFontMake(20), NSAttributedStringKey.kern: 0 as AnyObject]
    @objc dynamic public var sheetButtonDisabledAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor(r: 129, g: 129, b: 129), NSAttributedStringKey.font: UIFontMake(20), NSAttributedStringKey.kern: 0 as AnyObject] {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// sheet cancel 按钮样式，默认 [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFontBoldMake(20), NSAttributedStringKey.kern: 0 as AnyObject]
    @objc dynamic public var sheetCancelButtonAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.font: UIFontBoldMake(20), NSAttributedStringKey.kern: 0 as AnyObject] {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// sheet destructive 按钮样式，默认 [NSAttributedStringKey.foregroundColor: UIColor.red, NSAttributedStringKey.font: UIFontBoldMake(20), NSAttributedStringKey.kern: 0 as AnyObject]
    @objc dynamic public var sheetDestructiveButtonAttributes: [NSAttributedStringKey: AnyObject] = [NSAttributedStringKey.foregroundColor: UIColor.red, NSAttributedStringKey.font: UIFontBoldMake(20), NSAttributedStringKey.kern: 0 as AnyObject] {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// sheet cancel 按钮距离其上面元素（按钮或者header）的间距，默认8pt
    @objc dynamic public var sheetCancelButtonMarginTop: CGFloat = 8
    
    /// sheet内容的圆角，默认值是：(IOS_VERSION >= 9.0 ? 13 : 6)，以保持与系统默认样式一致
    @objc dynamic public var sheetContentCornerRadius: CGFloat = (IOS_VERSION >= 9.0 ? 13 : 6) {
        didSet {
            updateCornerRadius()
        }
    }
    
    /// sheet按钮高度，默认值是：(IOS_VERSION >= 9.0 ? 57 : 44)，以保持与系统默认样式一致
    @objc dynamic public var sheetButtonHeight: CGFloat = (IOS_VERSION >= 9.0 ? 57 : 44)
    
    /// sheet头部（非按钮部分）背景色，默认值是：UIColorMakeWithRGBA(247, 247, 247, 1)
    @objc dynamic public var sheetHeaderBackgroundColor: UIColor = UIColor(r: 247, g: 247, b: 247, a: 1) {
        didSet {
            updateHeaderBackgrondColor()
        }
    }
    
    /// sheet按钮背景色，默认值同`sheetHeaderBackgroundColor`
    @objc dynamic public var sheetButtonBackgroundColor: UIColor = UIColor(r: 247, g: 247, b: 247, a: 1) {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// sheet按钮高亮背景色，默认 UIColor(r: 232, g: 232, b: 232)
    @objc dynamic public var sheetButtonHighlightBackgroundColor: UIColor = UIColor(r: 232, g: 232, b: 232) {
        didSet {
            _needsUpdateAction = true
        }
    }
    
    /// sheet头部四边insets间距
    @objc dynamic public var sheetHeaderInsets: UIEdgeInsets = UIEdgeInsetsMake(16, 16, 16, 16)
    
    /// sheet头部title和message之间的间距，默认8pt
    @objc dynamic public var sheetTitleMessageSpacing: CGFloat = 8
    
    /// 所有`QMUIAlertAction`对象
    private(set) var actions: [QMUIAlertAction]?
    
    /// 当前所有通过`addTextFieldWithConfigurationHandler:`接口添加的输入框
    private(set) var textFields: [QMUITextField]?
    
    /// 设置自定义view。通过`addCustomView:`方法添加一个自定义的view，`QMUIAlertController`会在布局的时候去掉用这个view的`sizeThatFits:`方法来获取size，至于x和y坐标则由控件自己控制。
    private(set) var customView: UIView?
    
    /// 当前样式style
    private(set) var preferredStyle: QMUIAlertControllerStyle? {
        didSet {
            preferredStyle = IS_IPAD ? .alert : preferredStyle
        }
    }
    
    /// 将`QMUIAlertController`弹出来的`QMUIModalPresentationViewController`对象
    private(set) var modalPresentationViewController: QMUIModalPresentationViewController?
    
    /// 当前标题title
    override public var title: String? {
        get {
            return super.title
        }

//        alertController.alertContentMargin = UIEdgeInsetsMake(0, 0, 0, 0)
//        alertControllerAppearance = alertController
//    }
// }

// MARK: QMUIAlertAction

