AZDialogView 1.3.8

AZDialogView 1.3.8

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2019年7月
SPM支持 SPM

Antonio Zaitoun 维护。



  • Antonio Zaitoun

AZDialogViewController

这是一个高度可自定义的提醒对话框控制器,模仿 Snapchat 的提醒对话框。

CocoaPods CocoaPods CocoaPods

截图


安装

CocoaPods

pod 'AZDialogView'

Carthage

github "Minitour/AZDialogViewController"

用户手册

将“源”文件夹简单拖放到您的项目中。

使用说明

创建AZDialogViewController实例

//init with optional parameters
let dialog = AZDialogViewController(title: "Antonio Zaitoun", message: "minitour")

自定义

//set the title color
dialog.titleColor = .black

//set the message color
dialog.messageColor = .black

//set the dialog background color
dialog.alertBackgroundColor = .white

//set the gesture dismiss direction
dialog.dismissDirection = .bottom

//allow dismiss by touching the background
dialog.dismissWithOutsideTouch = true

//show seperator under the title
dialog.showSeparator = false

//set the seperator color
dialog.separatorColor = UIColor.blue

//enable/disable drag
dialog.allowDragGesture = false

//enable rubber (bounce) effect
dialog.rubberEnabled = true

//set dialog image
dialog.image = UIImage(named: "icon")

//enable/disable backgroud blur
dialog.blurBackground = true

//set the background blur style
dialog.blurEffectStyle = .dark

//set the dialog offset (from center)
dialog.contentOffset = self.view.frame.height / 2.0 - dialog.estimatedHeight / 2.0 - 16.0

添加动作

dialog.addAction(AZDialogAction(title: "Edit Name") { (dialog) -> (Void) in
        //add your actions here.
        dialog.dismiss()
})
        
dialog.addAction(AZDialogAction(title: "Remove Friend") { (dialog) -> (Void) in
        //add your actions here.
        dialog.dismiss()
})
        
dialog.addAction(AZDialogAction(title: "Block") { (dialog) -> (Void) in
        //add your actions here.
        dialog.dismiss()
})

添加图片

dialog.imageHandler = { (imageView) in
       imageView.image = UIImage(named: "your_image_here")
       imageView.contentMode = .scaleAspectFill
       return true //must return true, otherwise image won't show.
}

自定义视图

/*
 customViewSizeRatio is the precentage of the height in respect to the width of the view. 
 i.e. if the width is 100 and we set customViewSizeRatio to be 0.2 then the height will be 20. 
 The default value is 0.0.
*/
dialog.customViewSizeRatio = 0.2

//Add the subviews
let container = dialog.container
let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
dialog.container.addSubview(indicator)

//add constraints
indicator.translatesAutoresizingMaskIntoConstraints = false
indicator.centerXAnchor.constraint(equalTo: container.centerXAnchor).isActive = true
indicator.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true
indicator.startAnimating()

展示对话框

dialog.show(in: self)

//or

//Make sure to have animated set to false otherwise you'll see a delay.
self.present(dialog, animated: false, completion: nil)

显示并完成

dialog.show(in: self) { dialog in
    // show and then change the offset
    dialog.contentOffset = self.view.frame.height / 2.0 - dialog.estimatedHeight / 2.0 + 15
}

设计

更改对话框宽度

这是一个被请求的功能,所以我决定添加它。您可以将对话框框架的宽度更改为主视图宽度的比例。这只能通过初始化器实现,并且宽度之后不能修改。

let dialog = AZDialogViewController(title: "Switch Account", message: "My Message", widthRatio: 1.0)

这将显示一个具有与其控制器相同宽度的对话框。

默认值为 0.75

自定义操作按钮样式

dialog.buttonStyle = { (button,height,position) in
     button.setBackgroundImage(UIImage.imageWithColor(self.primaryColorDark), for: .highlighted)
     button.setTitleColor(UIColor.white, for: .highlighted)
     button.setTitleColor(self.primaryColor, for: .normal)
     button.layer.masksToBounds = true
     button.layer.borderColor = self.primaryColor.cgColor
}

使用自定义 UIButton 子类

dialog.buttonInit = { index in
    //set a custom button only for the first index
    return index == 0 ? HighlightableButton() : nil
}

自定义工具按钮

dialog.rightToolStyle = { (button) in
        button.setImage(UIImage(named: "ic_share"), for: [])
        button.tintColor = .lightGray
        return true
}      
dialog.rightToolAction = { (button) in
        print("Share function")
}

dialog.leftToolStyle = { (button) in
        button.setImage(UIImage(named: "ic_share"), for: [])
        button.tintColor = .lightGray
        return true
}      
dialog.leftToolAction = { (button) in
        print("Share function")
}

自定义取消按钮样式

dialog.cancelEnabled = true

dialog.cancelButtonStyle = { (button,height) in
        button.tintColor = self.primaryColor
        button.setTitle("CANCEL", for: [])
        return true //must return true, otherwise cancel button won't show.
}