mirror of https://github.com/xaoxuu/ProHUD
update readme
This commit is contained in:
parent
410b25955f
commit
c456398701
|
@ -46,19 +46,17 @@ class AlertVC: ListVC {
|
|||
Alert(.loading(3)).push()
|
||||
}
|
||||
section.add(title: "图标 + 文字") {
|
||||
Alert(.loading(4).message("正在加载")) { alert in
|
||||
alert.update(progress: 0)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
|
||||
alert.update(progress: 0.01)
|
||||
Alert(.loading.message("正在加载")) { alert in
|
||||
updateProgress(in: 4) { percent in
|
||||
alert.update(progress: percent)
|
||||
} completion: {
|
||||
alert.update { alert in
|
||||
alert.vm = .success.message("加载成功")
|
||||
alert.add(action: "OK")
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
alert.update(progress: 0.33)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()+2) {
|
||||
alert.pop()
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
|
||||
alert.update(progress: 0.67)
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
|
||||
alert.update(progress: 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
|
@ -38,7 +38,7 @@ class TableHeaderView: UIView {
|
|||
addSubview(titleLabel)
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.left.right.equalToSuperview().inset(24)
|
||||
make.top.equalToSuperview().offset(20)
|
||||
make.top.equalToSuperview().offset(28)
|
||||
}
|
||||
detailLabel.snp.makeConstraints { make in
|
||||
make.left.right.equalTo(titleLabel)
|
||||
|
|
|
@ -8,6 +8,29 @@
|
|||
import UIKit
|
||||
import ProHUD
|
||||
|
||||
|
||||
func updateProgress(in duration: TimeInterval, callback: @escaping (_ percent: CGFloat) -> Void, completion: (() -> Void)?) {
|
||||
let s = DispatchSemaphore(value: 1)
|
||||
DispatchQueue.global().async {
|
||||
let total = 50
|
||||
for i in 0 ... total {
|
||||
s.wait()
|
||||
DispatchQueue.main.async {
|
||||
callback(CGFloat(i)/CGFloat(total))
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + (duration / TimeInterval(total))) {
|
||||
s.signal()
|
||||
if i == total {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
||||
completion?()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ToastVC: ListVC {
|
||||
|
||||
override func viewDidLoad() {
|
||||
|
@ -25,7 +48,6 @@ class ToastVC: ListVC {
|
|||
}
|
||||
}
|
||||
|
||||
let vm: ViewModel = .loading
|
||||
list.add(title: "默认布局") { section in
|
||||
section.add(title: "标题 + 正文") {
|
||||
Toast(.title(title).message(message)).push()
|
||||
|
@ -34,20 +56,29 @@ class ToastVC: ListVC {
|
|||
Toast(.message(message)).push()
|
||||
}
|
||||
section.add(title: "图标 + 标题 + 正文") {
|
||||
let s1 = "正在加载"
|
||||
let s2 = "这条通知4s后消失"
|
||||
let toast = Toast(.loading(4).title(s1).message(s2))
|
||||
let s1 = "笑容正在加载"
|
||||
let s2 = "这通常不会太久"
|
||||
let toast = Toast(.loading.title(s1).message(s2))
|
||||
toast.push()
|
||||
toast.update(progress: 0)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
toast.update(progress: 0.5)
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
|
||||
toast.update(progress: 1)
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
|
||||
updateProgress(in: 4) { percent in
|
||||
toast.update(progress: percent)
|
||||
} completion: {
|
||||
toast.update { toast in
|
||||
toast.vm = .success(10).title("加载成功").message("这条通知10s后消失")
|
||||
toast.vm = .success(5).title("加载成功").message("这条通知5s后消失")
|
||||
toast.vm.icon = UIImage(named: "twemoji")
|
||||
}
|
||||
}
|
||||
}
|
||||
section.add(title: "倒计时") {
|
||||
let s1 = "笑容正在消失"
|
||||
let s2 = "这通常不会太久"
|
||||
Toast { toast in
|
||||
toast.vm = .title(s1).message(s2).icon(UIImage(named: "twemoji"))
|
||||
updateProgress(in: 5) { percent in
|
||||
toast.update(progress: 1 - percent)
|
||||
} completion: {
|
||||
toast.pop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ extension Alert: DefaultLayout {
|
|||
if contentView.superview != view {
|
||||
view.insertSubview(contentView, at: 0)
|
||||
}
|
||||
if config.enableShadow {
|
||||
if config.enableShadow && AlertWindow.alerts.count > 0 {
|
||||
contentView.clipsToBounds = false
|
||||
contentView.layer.shadowRadius = 4
|
||||
contentView.layer.shadowOpacity = 0.08
|
||||
|
@ -244,7 +244,7 @@ extension Alert {
|
|||
|
||||
public override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
if config.enableShadow {
|
||||
if config.enableShadow && AlertWindow.alerts.count > 1 {
|
||||
contentView.layer.shadowPath = UIBezierPath.init(rect: contentView.bounds).cgPath
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@ public extension Sheet {
|
|||
|
||||
override var cardMaxWidthByDefault: CGFloat { cardMaxWidth ?? 500 }
|
||||
|
||||
override var cardMaxHeightByDefault: CGFloat { cardMaxHeight ?? (UIScreen.main.bounds.height - 50) }
|
||||
|
||||
override var titleFontByDefault: UIFont {
|
||||
titleFont ?? .systemFont(ofSize: 24, weight: .bold)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue