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()
|
Alert(.loading(3)).push()
|
||||||
}
|
}
|
||||||
section.add(title: "图标 + 文字") {
|
section.add(title: "图标 + 文字") {
|
||||||
Alert(.loading(4).message("正在加载")) { alert in
|
Alert(.loading.message("正在加载")) { alert in
|
||||||
alert.update(progress: 0)
|
updateProgress(in: 4) { percent in
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
|
alert.update(progress: percent)
|
||||||
alert.update(progress: 0.01)
|
} completion: {
|
||||||
|
alert.update { alert in
|
||||||
|
alert.vm = .success.message("加载成功")
|
||||||
|
alert.add(action: "OK")
|
||||||
}
|
}
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
DispatchQueue.main.asyncAfter(deadline: .now()+2) {
|
||||||
alert.update(progress: 0.33)
|
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)
|
addSubview(titleLabel)
|
||||||
titleLabel.snp.makeConstraints { make in
|
titleLabel.snp.makeConstraints { make in
|
||||||
make.left.right.equalToSuperview().inset(24)
|
make.left.right.equalToSuperview().inset(24)
|
||||||
make.top.equalToSuperview().offset(20)
|
make.top.equalToSuperview().offset(28)
|
||||||
}
|
}
|
||||||
detailLabel.snp.makeConstraints { make in
|
detailLabel.snp.makeConstraints { make in
|
||||||
make.left.right.equalTo(titleLabel)
|
make.left.right.equalTo(titleLabel)
|
||||||
|
|
|
@ -8,6 +8,29 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
import ProHUD
|
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 {
|
class ToastVC: ListVC {
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
|
@ -25,7 +48,6 @@ class ToastVC: ListVC {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let vm: ViewModel = .loading
|
|
||||||
list.add(title: "默认布局") { section in
|
list.add(title: "默认布局") { section in
|
||||||
section.add(title: "标题 + 正文") {
|
section.add(title: "标题 + 正文") {
|
||||||
Toast(.title(title).message(message)).push()
|
Toast(.title(title).message(message)).push()
|
||||||
|
@ -34,20 +56,29 @@ class ToastVC: ListVC {
|
||||||
Toast(.message(message)).push()
|
Toast(.message(message)).push()
|
||||||
}
|
}
|
||||||
section.add(title: "图标 + 标题 + 正文") {
|
section.add(title: "图标 + 标题 + 正文") {
|
||||||
let s1 = "正在加载"
|
let s1 = "笑容正在加载"
|
||||||
let s2 = "这条通知4s后消失"
|
let s2 = "这通常不会太久"
|
||||||
let toast = Toast(.loading(4).title(s1).message(s2))
|
let toast = Toast(.loading.title(s1).message(s2))
|
||||||
toast.push()
|
toast.push()
|
||||||
toast.update(progress: 0)
|
toast.update(progress: 0)
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
updateProgress(in: 4) { percent in
|
||||||
toast.update(progress: 0.5)
|
toast.update(progress: percent)
|
||||||
}
|
} completion: {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
|
|
||||||
toast.update(progress: 1)
|
|
||||||
}
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
|
|
||||||
toast.update { toast in
|
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 {
|
if contentView.superview != view {
|
||||||
view.insertSubview(contentView, at: 0)
|
view.insertSubview(contentView, at: 0)
|
||||||
}
|
}
|
||||||
if config.enableShadow {
|
if config.enableShadow && AlertWindow.alerts.count > 0 {
|
||||||
contentView.clipsToBounds = false
|
contentView.clipsToBounds = false
|
||||||
contentView.layer.shadowRadius = 4
|
contentView.layer.shadowRadius = 4
|
||||||
contentView.layer.shadowOpacity = 0.08
|
contentView.layer.shadowOpacity = 0.08
|
||||||
|
@ -244,7 +244,7 @@ extension Alert {
|
||||||
|
|
||||||
public override func viewDidLayoutSubviews() {
|
public override func viewDidLayoutSubviews() {
|
||||||
super.viewDidLayoutSubviews()
|
super.viewDidLayoutSubviews()
|
||||||
if config.enableShadow {
|
if config.enableShadow && AlertWindow.alerts.count > 1 {
|
||||||
contentView.layer.shadowPath = UIBezierPath.init(rect: contentView.bounds).cgPath
|
contentView.layer.shadowPath = UIBezierPath.init(rect: contentView.bounds).cgPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@ public extension Sheet {
|
||||||
|
|
||||||
override var cardMaxWidthByDefault: CGFloat { cardMaxWidth ?? 500 }
|
override var cardMaxWidthByDefault: CGFloat { cardMaxWidth ?? 500 }
|
||||||
|
|
||||||
|
override var cardMaxHeightByDefault: CGFloat { cardMaxHeight ?? (UIScreen.main.bounds.height - 50) }
|
||||||
|
|
||||||
override var titleFontByDefault: UIFont {
|
override var titleFontByDefault: UIFont {
|
||||||
titleFont ?? .systemFont(ofSize: 24, weight: .bold)
|
titleFont ?? .systemFont(ofSize: 24, weight: .bold)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue