swift alertView的写法及一些宏定义

2018-01-17  本文已影响0人  艾尔之光_熊

//提示弹窗消息并自动消失方法

 func showAlertMessage(message:NSString?, duration:Float){

            let alertController = UIAlertController(title: "", message: message as String?,preferredStyle:.alert)

            self.present(alertController, animated: true, completion: nil)

            self.perform(#selector(dimissAlert), with: alertController, afterDelay: TimeInterval(duration))

    }

@objc func dimissAlert(alert:UIAlertController) {

            alert.dismiss(animated: true, completion: nil)

}

一些简单的宏定义

let ScreenHeight:CGFloat = UIScreen.main.bounds.size.height//屏幕高度

let ScreenWidth:CGFloat = UIScreen.main.bounds.size.width//屏幕宽度

let NavigationHeight = (ScreenHeight == 812.0) ? 88 : 64//判断是否iPhone X,返回不同的导航栏高度

上一篇下一篇

猜你喜欢

热点阅读