Swift 简单的弹框提示

2018-06-05  本文已影响0人  novice_Qin

这是一个简单,易用,代码比较少的swift弹框提示,能根据文本高度,自行调整位置和弹框高度

1.0

没有点击按钮时候没有显示的弹框

1.1

点击按钮出现一个提示弹框

1.2

具体代码如下:

let titleLabel = UILabel()

                titleLabel.text = languageStr("Login successful")

                titleLabel.backgroundColor = titleutColor

                titleLabel.font = UIFont.systemFont(ofSize: 17)

                titleLabel.textAlignment = NSTextAlignment.center

                titleLabel.textColor = UIColor.white

                titleLabel.layer.cornerRadius = 5

                titleLabel.layer.masksToBounds = true

                titleLabel.numberOfLines = 0

                titleLabel.frame = CGRect.init(x: KScreenWidth * 0.24, y: KScreenHeight * 0.73, width: KScreenWidth * 0.6, height: KScreenHeight * 0.05)

                UIView.animate(withDuration: 0.5, animations: {

                    self.view.addSubview(titleLabel)

                },  completion: {(b:Bool) -> Void in

                    DispatchQueue.main.asyncAfter(deadline: .now() + 1) {//弹出以后一秒后自行消失

                        titleLabel.removeFromSuperview()

                        weakSelf?.showAllCureenView()

                    }

                })

新手一枚刚开始写简书文章,不喜勿喷。欢迎大牛来指导技术 Q1255130032

上一篇 下一篇

猜你喜欢

热点阅读