SCLAlertView(提醒框)的基本使用(swift)

github地址

1、最基本的提示框
SCLAlertView(提醒框)的基本使用(swift)_第1张图片
SCLAlertView().showInfo("基本提示框", subTitle: "消息内容大沙发沙发上")

2、根据需求添加不同风格 输入框、按钮
SCLAlertView(提醒框)的基本使用(swift)_第2张图片
 let alertView = SCLAlertView()
            // 添加一个有等待文字的TextField
            let waitingTextField = alertView.addTextField("我是等待文字")
            // 天机一个textView
            let textView = alertView.addTextView()
            // 添加一个没有等待文字的TextField
            let textField = alertView.addTextField()
            
            // 添加一个按钮,自定义事件
            alertView.addButton("第一个", target:self, selector:#selector(firstButton))
            
            // 添加一个按钮,Block处理事件
            alertView.addButton("第二个") {
                print("waitingTextField输入的文字:\(waitingTextField.text)")
            }
            
            // 添加一个按钮,Block处理事件
            alertView.addButton("第三个", action: { 
                print("textView输入的文字:\(textView.text)")
            })
            
            // 添加一个自定义属性的按钮,Block处理事件
            alertView.addButton("第四个", backgroundColor: UIColor.red, textColor: UIColor.white, showDurationStatus: true, action: {
                print("textField输入的文字:\(textField.text)")
            })
            // 决定显示什么类型的提醒框(成功,错误,警告等)
            alertView.showSuccess("Button View", subTitle: "This alert view has buttons")

3、没有按钮,设定时间自动消失
SCLAlertView(提醒框)的基本使用(swift)_第3张图片
let appearance = SCLAlertView.SCLAppearance(
     showCloseButton: false
)
let alertView = SCLAlertView(appearance: appearance)
alertView.showWarning("没有按钮", subTitle: "等待3秒,我将会消失", duration: 3)

4、 没有图片
SCLAlertView(提醒框)的基本使用(swift)_第4张图片
let appearance = SCLAlertView.SCLAppearance(
    showCircularIcon: false
)
let alertView = SCLAlertView(appearance: appearance)
alertView.showSuccess("没有图片", subTitle: "这是一个干净的警报没有图标!")

5、自定义图片
SCLAlertView(提醒框)的基本使用(swift)_第5张图片
let appearance = SCLAlertView.SCLAppearance(
    showCircularIcon: true
)
let alertView = SCLAlertView(appearance: appearance)
let alertViewIcon = UIImage(named: "123")
alertView.showInfo("自定义图片", subTitle: "这是一个很好的提醒你选择自定义图标", circleIconImage: alertViewIcon)

6、添加一个输入框
SCLAlertView(提醒框)的基本使用(swift)_第6张图片
let alert = SCLAlertView()
let txt = alert.addTextField("等待文字")
alert.addButton("显示输入内容") {
   print("Text value: \(txt.text)")
}
alert.showEdit("编辑视图", subTitle: "这个警报视图显示一个文本框")

7、完全自定义(常用)
SCLAlertView(提醒框)的基本使用(swift)_第7张图片
// (参数定义)自定义标题,内容,取消按钮文字,显示时长,图标背景、取消按钮背景颜色,取消按钮字体颜色,自定义icon,从哪个方向进入视图中
SCLAlertView().showSuccess("什么?", subTitle: "wateringdfasfsafasfsaffsfffasfsfsafsfasfsf", closeButtonTitle: "完成", duration: 30, colorStyle: 0xA429FF, colorTextButton: 0xFFFFFF, circleIconImage: UIImage(named:"123"), animationStyle: .leftToRight)

你可能感兴趣的:(SCLAlertView(提醒框)的基本使用(swift))