diff --git a/Example-Old/Example/AppDelegate.swift b/Example-Old/Example/AppDelegate.swift index 2e17f46..f5ecd4f 100644 --- a/Example-Old/Example/AppDelegate.swift +++ b/Example-Old/Example/AppDelegate.swift @@ -26,22 +26,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // 可自动获取根控制器,如果获取失败请主动设置此值 // cfg.rootViewController = vc cfg.alert { (a) in - a.titleFont = .bold(22) - a.bodyFont = .regular(17) - a.boldTextFont = .bold(18) - a.buttonFont = .bold(18) +// a.titleFont = .bold(22) +// a.bodyFont = .regular(17) +// a.boldTextFont = .bold(18) +// a.buttonFont = .bold(18) a.forceQuitTimer = 3 } - cfg.toast { (t) in - t.titleFont = .bold(18) - t.bodyFont = .regular(16) - } - cfg.guard { (g) in - g.titleFont = .bold(22) - g.subTitleFont = .bold(20) - g.bodyFont = .regular(17) - g.buttonFont = .bold(18) - } +// cfg.toast { (t) in +// t.titleFont = .bold(18) +// t.bodyFont = .regular(16) +// t.iconSize = .init(width: 42, height: 42) +// } +// cfg.guard { (g) in +// g.titleFont = .bold(22) +// g.subTitleFont = .bold(20) +// g.bodyFont = .regular(17) +// g.buttonFont = .bold(18) +// } } return true diff --git a/Example-Old/Example/TestToastVC.swift b/Example-Old/Example/TestToastVC.swift index b3df1e7..7a3a91d 100644 --- a/Example-Old/Example/TestToastVC.swift +++ b/Example-Old/Example/TestToastVC.swift @@ -28,7 +28,8 @@ class TestToastVC: BaseListVC { "避免重复发布同一条信息", "根据id查找并修改实例", "测试较长的标题和内容", - "测试特别长的标题和内容"] + "测试特别长的标题和内容", + "测试只有message"] } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { @@ -129,6 +130,14 @@ class TestToastVC: BaseListVC { vm.title = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过" vm.message = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过" + } + } + } else if row == 11 { + Toast.push() { (a) in + a.update { (vm) in + vm.scene = .warning + vm.message = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过" + } } } diff --git a/Example-Old/Podfile.lock b/Example-Old/Podfile.lock index cb8ef97..daef591 100644 --- a/Example-Old/Podfile.lock +++ b/Example-Old/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - Inspire (1.1.0) + - Inspire (2.0.0) - ProHUD (1.0): - Inspire - SnapKit (= 5.0) @@ -21,7 +21,7 @@ EXTERNAL SOURCES: :path: ".." SPEC CHECKSUMS: - Inspire: 0beb2517cbf0111fe13c6bb1ab9ea791abd1f42b + Inspire: 7556357c9c90d5e886f3be5d29fe1e0222b694e1 ProHUD: 7128b55036885ac4f8b4d0b0783ee6f8eb3a2ea9 SnapKit: fd22d10eb9aff484d79a8724eab922c1ddf89bcf diff --git a/Source/Toast/ToastConfig.swift b/Source/Toast/ToastConfig.swift index ffca220..7d1501b 100644 --- a/Source/Toast/ToastConfig.swift +++ b/Source/Toast/ToastConfig.swift @@ -20,10 +20,11 @@ public extension ProHUD.Configuration { public var margin = CGFloat(8) /// 填充:元素内部控件距离元素边界的距离 public var padding = CGFloat(16) - + /// 行间距 + public var lineSpace = CGFloat(4) // MARK: 图标样式 /// 图标尺寸 - public var iconSize = CGSize(width: 48, height: 48) + public var iconSize = CGSize(width: 24, height: 24) // MARK: 文本样式 /// 标题字体 @@ -63,15 +64,15 @@ fileprivate var privReloadData: (ProHUD.Toast) -> Void = { debug(vc, "reloadData") let config = cfg.toast let scene = vc.vm.scene - if vc.titleLabel.superview == nil { - vc.view.addSubview(vc.titleLabel) - } - if vc.bodyLabel.superview == nil { - vc.view.addSubview(vc.bodyLabel) - } if vc.imageView.superview == nil { vc.view.addSubview(vc.imageView) } + if vc.textStack.superview == nil { + vc.view.addSubview(vc.textStack) + vc.textStack.addArrangedSubview(vc.titleLabel) + vc.textStack.addArrangedSubview(vc.bodyLabel) + } + // 设置数据 vc.imageView.image = vc.vm.icon ?? vc.vm.scene.image vc.imageView.layer.removeAllAnimations() @@ -80,6 +81,17 @@ fileprivate var privReloadData: (ProHUD.Toast) -> Void = { vc.bodyLabel.textColor = cfg.secondaryLabelColor vc.bodyLabel.text = vc.vm.message ?? vc.vm.scene.message + if let count = vc.titleLabel.text?.count, count > 0 { + vc.textStack.insertArrangedSubview(vc.titleLabel, at: 0) + } else { + vc.titleLabel.removeFromSuperview() + } + if let count = vc.bodyLabel.text?.count, count > 0 { + vc.textStack.addArrangedSubview(vc.bodyLabel) + } else { + vc.bodyLabel.removeFromSuperview() + } + // 更新布局 vc.imageView.snp.makeConstraints { (mk) in mk.top.equalToSuperview().offset(config.padding) @@ -87,17 +99,24 @@ fileprivate var privReloadData: (ProHUD.Toast) -> Void = { mk.bottom.lessThanOrEqualToSuperview().offset(-config.padding) mk.width.height.equalTo(config.iconSize) } - vc.titleLabel.snp.makeConstraints { (mk) in + vc.textStack.snp.makeConstraints { (mk) in mk.top.equalToSuperview().offset(config.padding) - mk.leading.equalTo(vc.imageView.snp.trailing).offset(config.margin) + mk.leading.equalTo(vc.imageView.snp.trailing).offset(config.padding - 4) mk.leading.greaterThanOrEqualToSuperview().offset(config.padding) mk.trailing.equalToSuperview().offset(-config.padding) - } - vc.bodyLabel.snp.makeConstraints { (mk) in - mk.top.equalTo(vc.titleLabel.snp.bottom).offset(config.margin) - mk.leading.trailing.equalTo(vc.titleLabel) mk.bottom.lessThanOrEqualToSuperview().offset(-config.padding) } +// vc.titleLabel.snp.makeConstraints { (mk) in +// mk.top.equalToSuperview().offset(config.padding) +// mk.leading.equalTo(vc.imageView.snp.trailing).offset(config.padding - 4) +// mk.leading.greaterThanOrEqualToSuperview().offset(config.padding) +// mk.trailing.equalToSuperview().offset(-config.padding) +// } +// vc.bodyLabel.snp.makeConstraints { (mk) in +// mk.top.equalTo(vc.titleLabel.snp.bottom).offset(config.lineSpace) +// mk.leading.trailing.equalTo(vc.titleLabel) +// mk.bottom.lessThanOrEqualToSuperview().offset(-config.padding) +// } vc.view.layoutIfNeeded() diff --git a/Source/Toast/ToastController.swift b/Source/Toast/ToastController.swift index fcf7e52..6b9e975 100644 --- a/Source/Toast/ToastController.swift +++ b/Source/Toast/ToastController.swift @@ -25,6 +25,14 @@ public extension ProHUD { return imgv }() + /// 文本区容器 + public var textStack: StackContainer = { + let stack = StackContainer() + stack.spacing = cfg.toast.lineSpace + stack.alignment = .fill + return stack + }() + /// 标题 public lazy var titleLabel: UILabel = { let lb = UILabel()