我是iOS开发的新手。我想在完成某些操作时通知用户。在Android中他们提供了小吃店来实现这一点。我看到了很多库。我不确定哪个是所有iOS设备的标准库支持。
https://www.cocoacontrols.com/search?q=notification
先谢谢
答案 0 :(得分:0)
我不知道是否有一个是标准的,但我使用的https://github.com/Daltron/NotificationBanner效果非常好并且仍在维护。
答案 1 :(得分:0)
您可以创建 UIViewController 的扩展名,并根据位置在其上显示标签。
enum ToastPosition {
case top
case down
}
extension UIViewController {
func show(toastWith message : String, font: UIFont = UIFont.systemFont(ofSize: 12) ,toastPosition: ToastPosition,backgroundColor: UIColor = .black,textColor: UIColor = .white, duration: TimeInterval = 3.0) {
let yPostition = toastPosition == .top ? 24 : self.view.frame.size.height - 44 - 16//margin
let frame = CGRect(x: self.view.frame.size.width/2 - 64, y: yPostition, width: 150, height: 44)
let toast = UILabel(frame: frame)
toast.backgroundColor = backgroundColor.withAlphaComponent(0.7)
toast.textColor = textColor
toast.textAlignment = .center;
toast.font = font
toast.text = message
toast.alpha = 1.0
toast.layer.cornerRadius = 10;
toast.clipsToBounds = true
self.view.addSubview(toast)
UIView.animate(withDuration: duration, delay: 0.1, options: .curveEaseInOut, animations: {
toast.alpha = 0.0
}, completion: {(isCompleted) in
toast.removeFromSuperview()
})
}
}