diff --git a/PHDemo/PHDemo/AlertVC.swift b/PHDemo/PHDemo/AlertVC.swift index 72948b9..530310c 100644 --- a/PHDemo/PHDemo/AlertVC.swift +++ b/PHDemo/PHDemo/AlertVC.swift @@ -71,14 +71,17 @@ class AlertVC: ListVC { list.add(title: "文字 + 按钮") { section in section.add(title: "只有一小段文字 + 无背景色按钮") { Alert { alert in + alert.config.cardMinWidth = 270 + alert.config.cardEdgeInsets = .init(top: 0, left: 0, bottom: 16, right: 0) + alert.config.textEdgeInsets = .init(top: 30, left: 32, bottom: 30, right: 32) alert.config.cardCornerRadius = 12 - alert.vm.title = "你正在使用移动网络观看" alert.config.customTextLabel { label in label.font = .systemFont(ofSize: 15) } alert.config.customButton { button in button.titleLabel?.font = .systemFont(ofSize: 15) } + alert.vm.title = "你正在使用移动网络观看" } .onViewDidLoad { vc in guard let alert = vc as? Alert else { return @@ -97,14 +100,17 @@ class AlertVC: ListVC { } section.add(title: "只有一段文字 + 无背景色按钮") { Alert { alert in + alert.config.cardMinWidth = 270 + alert.config.cardEdgeInsets = .init(top: 0, left: 0, bottom: 16, right: 0) + alert.config.textEdgeInsets = .init(top: 30, left: 32, bottom: 30, right: 32) alert.config.cardCornerRadius = 12 - alert.vm.title = "为了维护社区氛围,上麦用户需进行主播认证" - alert.config.customBodyLabel { label in + alert.config.customTextLabel { label in label.font = .systemFont(ofSize: 15) } alert.config.customButton { button in button.titleLabel?.font = .systemFont(ofSize: 15) } + alert.vm.message = "为了维护社区氛围,上麦用户需进行主播认证" } .onViewDidLoad { vc in guard let alert = vc as? Alert else { return @@ -315,7 +321,7 @@ class AlertVC: ListVC { slider.maximumValue = 100 slider.value = 50 alert.add(action: slider) - alert.add(actionSpacing: 124) + alert.add(actionSpacing: 24) alert.add(action: "取消", style: .gray) } } diff --git a/PHDemo/PHDemo/SheetVC.swift b/PHDemo/PHDemo/SheetVC.swift index 53e8743..18532f2 100644 --- a/PHDemo/PHDemo/SheetVC.swift +++ b/PHDemo/PHDemo/SheetVC.swift @@ -81,7 +81,6 @@ class SheetVC: ListVC { toast.vm.message = "点击背景将不会dismiss,必须在下方做出选择才能关掉" toast.vm.duration = 2 } - } } } @@ -112,13 +111,13 @@ class SheetVC: ListVC { let s2 = UISlider() s2.minimumValue = 0 s2.maximumValue = 40 - s2.value = Float(sheet.config.edgeInset) + s2.value = Float(sheet.config.screenEdgeInset) sheet.add(subview: s2).snp.makeConstraints { make in make.height.equalTo(50) } if #available(iOS 14.0, *) { s2.addAction(.init(handler: { [unowned s2] act in - sheet.config.edgeInset = CGFloat(s2.value) + sheet.config.screenEdgeInset = CGFloat(s2.value) sheet.reloadData() }), for: .valueChanged) } else { diff --git a/PHDemo/PHDemo/ToastVC.swift b/PHDemo/PHDemo/ToastVC.swift index 0023414..99ab424 100644 --- a/PHDemo/PHDemo/ToastVC.swift +++ b/PHDemo/PHDemo/ToastVC.swift @@ -155,7 +155,9 @@ class ToastVC: ListVC { list.add(title: "实例管理") { section in var i = 0 section.add(title: "多实例共存") { - Toast(.loading.title("多实例共存").message("直接创建的实例,以平铺方式排列").duration(2)).push() + Toast(.loading.title("多实例共存").message("直接创建的实例,以平铺方式排列").duration(2)) { toast in + toast.config.cardEdgeInsets = .init(top: 32, left: 20, bottom: 32, right: 20) + } } section.add(title: "不存在就创建,存在就更新") { i += 1 @@ -244,12 +246,12 @@ class ToastVC: ListVC { lb.textAlignment = .center stack.addArrangedSubview(lb) - let btn1 = ProHUD.Button(config: toast.config, action: .init(style: .gray, title: "取消")) + let btn1 = ProHUD.ToastButton(config: toast.config, action: .init(style: .gray, title: "取消")) btn1.onTouchUpInside { action in print("点击了取消") testAlert() } - let btn2 = ProHUD.Button(config: toast.config, action: .init(style: .tinted, title: "确定")) + let btn2 = ProHUD.ToastButton(config: toast.config, action: .init(style: .tinted, title: "确定")) btn2.onTouchUp { action in print("点击了确定") testAlert() diff --git a/Sources/ProHUD/Alert/Alert.swift b/Sources/ProHUD/Alert/Alert.swift index 0d31837..88b785b 100644 --- a/Sources/ProHUD/Alert/Alert.swift +++ b/Sources/ProHUD/Alert/Alert.swift @@ -20,16 +20,18 @@ public class Alert: ProHUD.Controller { /// 内容容器(包括icon、textStack、actionStack) public lazy var contentStack: StackView = { let stack = StackView(axis: .vertical) - stack.spacing = config.margin + stack.spacing = 24 stack.alignment = .center + config.customContentStack?(stack) return stack }() /// 文本区容器 public lazy var textStack: StackView = { let stack = StackView(axis: .vertical) - stack.spacing = config.margin + stack.spacing = 8 stack.alignment = .center + config.customTextStack?(stack) return stack }() @@ -66,7 +68,8 @@ public class Alert: ProHUD.Controller { let stack = StackView() stack.alignment = .fill stack.distribution = .fillEqually - stack.spacing = config.margin + stack.spacing = 8 + config.customActionStack?(stack) return stack }() diff --git a/Sources/ProHUD/Alert/AlertButton.swift b/Sources/ProHUD/Alert/AlertButton.swift index 52f7ca1..ac31d93 100644 --- a/Sources/ProHUD/Alert/AlertButton.swift +++ b/Sources/ProHUD/Alert/AlertButton.swift @@ -15,6 +15,7 @@ public class AlertButton: Button { public override func update(config: ProHUD.Configuration, action: Action) { titleLabel?.font = .boldSystemFont(ofSize: 15) + layer.cornerRadiusWithContinuous = 8 super.update(config: config, action: action) } diff --git a/Sources/ProHUD/Alert/AlertConfiguration.swift b/Sources/ProHUD/Alert/AlertConfiguration.swift index a041f3a..071ab4d 100644 --- a/Sources/ProHUD/Alert/AlertConfiguration.swift +++ b/Sources/ProHUD/Alert/AlertConfiguration.swift @@ -11,6 +11,7 @@ public extension Alert { class Configuration: ProHUD.Configuration { + /// 指定排列方向(默认两个按钮水平排列,超过时垂直排列) public var actionAxis: NSLayoutConstraint.Axis? diff --git a/Sources/ProHUD/Alert/AlertDefaultLayout.swift b/Sources/ProHUD/Alert/AlertDefaultLayout.swift index 1fccdfb..62c730f 100644 --- a/Sources/ProHUD/Alert/AlertDefaultLayout.swift +++ b/Sources/ProHUD/Alert/AlertDefaultLayout.swift @@ -84,17 +84,19 @@ extension Alert: DefaultLayout { contentView.snp.remakeConstraints { make in make.center.equalToSuperview() if customView == nil { - make.width.greaterThanOrEqualTo(config.cardMinWidth).priority(.low) + make.width.greaterThanOrEqualTo(config.cardMinWidth) make.width.lessThanOrEqualTo(config.cardMaxWidthByDefault) - make.height.greaterThanOrEqualTo(config.cardMinHeight).priority(.low) + make.height.greaterThanOrEqualTo(config.cardMinHeight) make.height.lessThanOrEqualTo(config.cardMaxHeightByDefault) } } if contentStack.superview == nil { contentView.addSubview(contentStack) - contentStack.spacing = config.margin + config.padding contentStack.snp.remakeConstraints { make in - make.edges.equalTo(contentView).inset(config.padding) + make.top.equalToSuperview().inset(config.cardEdgeInsets.top) + make.left.equalToSuperview().inset(config.cardEdgeInsets.left) + make.bottom.equalToSuperview().inset(config.cardEdgeInsets.bottom) + make.right.equalToSuperview().inset(config.cardEdgeInsets.right) } } // card background @@ -144,8 +146,8 @@ extension Alert { if imageView.superview == nil { contentStack.insertArrangedSubview(imageView, at: 0) imageView.snp.remakeConstraints { (mk) in - mk.top.left.greaterThanOrEqualTo(contentView).inset(config.padding*2.25) - mk.right.bottom.lessThanOrEqualTo(contentView).inset(config.padding*2.25) + mk.top.left.greaterThanOrEqualTo(contentView).inset(config.cardEdgeInsets.top * 2) + mk.right.bottom.lessThanOrEqualTo(contentView).inset(config.cardEdgeInsets.right * 2) mk.width.equalTo(config.iconSize.width) mk.height.equalTo(config.iconSize.height) } @@ -172,15 +174,10 @@ extension Alert { contentStack.insertArrangedSubview(textStack, at: 0) } textStack.snp.remakeConstraints { (mk) in - mk.top.greaterThanOrEqualTo(contentView).inset(config.padding*1.875) - mk.bottom.lessThanOrEqualTo(contentView).inset(config.padding*1.875) - if UIScreen.main.bounds.width < 414 { - mk.left.greaterThanOrEqualTo(contentView).inset(config.padding*2) - mk.right.lessThanOrEqualTo(contentView).inset(config.padding*2) - } else { - mk.left.greaterThanOrEqualTo(contentView).inset(config.padding*3) - mk.right.lessThanOrEqualTo(contentView).inset(config.padding*3) - } + mk.left.greaterThanOrEqualToSuperview().inset(config.textEdgeInsets.left) + mk.right.lessThanOrEqualToSuperview().inset(config.textEdgeInsets.right) + mk.top.greaterThanOrEqualTo(contentView).inset(config.cardEdgeInsets.top + config.textEdgeInsets.top) + mk.bottom.lessThanOrEqualTo(contentView).inset(config.cardEdgeInsets.bottom + config.textEdgeInsets.bottom) } } if titleCount > 0 { diff --git a/Sources/ProHUD/Alert/AlertManager.swift b/Sources/ProHUD/Alert/AlertManager.swift index af367d4..b71f0a1 100644 --- a/Sources/ProHUD/Alert/AlertManager.swift +++ b/Sources/ProHUD/Alert/AlertManager.swift @@ -73,7 +73,7 @@ public extension Alert { static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ alert: Alert) -> Void, onExists: ((_ alert: Alert) -> Void)? = nil) { let id = identifier ?? (file + "#\(line)") if let vc = AlertWindow.alerts.last(where: { $0.identifier == id }) { - onExists?(vc) + vc.update(handler: onExists ?? handler) } else { Alert { alert in alert.identifier = id diff --git a/Sources/ProHUD/Core/Models/Configuration.swift b/Sources/ProHUD/Core/Models/Configuration.swift index 8a1548d..9a0b9fe 100644 --- a/Sources/ProHUD/Core/Models/Configuration.swift +++ b/Sources/ProHUD/Core/Models/Configuration.swift @@ -90,18 +90,40 @@ public class Configuration: NSObject { /// 最小高度 public var cardMinHeight = CGFloat(32) + /// 卡片内边距 + public var cardEdgeInsets: UIEdgeInsets = { + .init(top: 16, left: 16, bottom: 16, right: 16) + }() + + /// 文字区域内边距 + public var textEdgeInsets: UIEdgeInsets = { + .init(top: 16, left: 16, bottom: 16, right: 16) + }() + /// 卡片圆角 public var cardCornerRadius: CGFloat? var cardCornerRadiusByDefault: CGFloat { cardCornerRadius ?? 16 } - /// 余量:元素与元素之间的距离 - public var margin = CGFloat(8) /// 填充:元素内部控件距离元素边界的距离 public var padding = CGFloat(16) /// 颜色 public var tintColor: UIColor? + + var customContentStack: ((_ stack: StackView) -> Void)? + public func customContentStack(handler: @escaping (_ stack: StackView) -> Void) { + customContentStack = handler + } + var customTextStack: ((_ stack: StackView) -> Void)? + public func customTextStack(handler: @escaping (_ stack: StackView) -> Void) { + customTextStack = handler + } + var customActionStack: ((_ stack: StackView) -> Void)? + public func customActionStack(handler: @escaping (_ stack: StackView) -> Void) { + customActionStack = handler + } + // MARK: 图标样式 /// 图标尺寸 public var iconSize = CGSize(width: 44, height: 44) @@ -144,10 +166,6 @@ public class Configuration: NSObject { customButton = handler } - /// 按钮圆角 - public var buttonCornerRadius: CGFloat? - var buttonCornerRadiusByDefault: CGFloat { buttonCornerRadius ?? 8 } - // MARK: 动画 public var animateDurationForBuildIn: TimeInterval? diff --git a/Sources/ProHUD/Core/Views/Button.swift b/Sources/ProHUD/Core/Views/Button.swift index 287642e..00c67ff 100644 --- a/Sources/ProHUD/Core/Views/Button.swift +++ b/Sources/ProHUD/Core/Views/Button.swift @@ -31,13 +31,13 @@ open class Button: UIButton { public convenience init(config: ProHUD.Configuration, action: Action) { self.init(frame: .zero) + layer.cornerRadiusWithContinuous = 8 self.update(config: config, action: action) } /// 更新按钮 /// - Parameter style: 样式 open func update(config: ProHUD.Configuration, action: Action) { - layer.cornerRadiusWithContinuous = config.buttonCornerRadiusByDefault self.action = action setTitle(action.title, for: .normal) switch action.style { diff --git a/Sources/ProHUD/Sheet/Sheet.swift b/Sources/ProHUD/Sheet/Sheet.swift index e34a9e0..635205e 100644 --- a/Sources/ProHUD/Sheet/Sheet.swift +++ b/Sources/ProHUD/Sheet/Sheet.swift @@ -27,8 +27,9 @@ public class Sheet: Controller { /// 内容容器(包括icon、textStack、actionStack) public lazy var contentStack: StackView = { let stack = StackView() - stack.spacing = config.margin + stack.spacing = 8 stack.alignment = .fill + config.customContentStack?(stack) return stack }() diff --git a/Sources/ProHUD/Sheet/SheetButton.swift b/Sources/ProHUD/Sheet/SheetButton.swift index 659d0a3..6a0d745 100644 --- a/Sources/ProHUD/Sheet/SheetButton.swift +++ b/Sources/ProHUD/Sheet/SheetButton.swift @@ -15,6 +15,7 @@ public class SheetButton: Button { public override func update(config: ProHUD.Configuration, action: Action) { titleLabel?.font = .boldSystemFont(ofSize: 18) + layer.cornerRadiusWithContinuous = 12 super.update(config: config, action: action) } diff --git a/Sources/ProHUD/Sheet/SheetConfiguration.swift b/Sources/ProHUD/Sheet/SheetConfiguration.swift index 6b91b6f..d846ca6 100644 --- a/Sources/ProHUD/Sheet/SheetConfiguration.swift +++ b/Sources/ProHUD/Sheet/SheetConfiguration.swift @@ -12,7 +12,7 @@ public extension Sheet { class Configuration: ProHUD.Configuration { /// 卡片距离屏幕的间距 - public var edgeInset: CGFloat = 4 + public var screenEdgeInset: CGFloat = 4 /// 是否是全屏的页面 public var isFullScreen = false @@ -45,8 +45,6 @@ public extension Sheet { override var cardMaxHeightByDefault: CGFloat { cardMaxHeight ?? (UIScreen.main.bounds.height - 50) } - override var buttonCornerRadiusByDefault: CGFloat { buttonCornerRadius ?? 12 } - override var animateDurationForBuildInByDefault: CGFloat { animateDurationForBuildIn ?? 0.5 } diff --git a/Sources/ProHUD/Sheet/SheetConvenienceLayout.swift b/Sources/ProHUD/Sheet/SheetConvenienceLayout.swift index 04642a8..151afac 100644 --- a/Sources/ProHUD/Sheet/SheetConvenienceLayout.swift +++ b/Sources/ProHUD/Sheet/SheetConvenienceLayout.swift @@ -153,10 +153,10 @@ public extension Sheet { if #available(iOS 11.0, *) { let count = contentStack.arrangedSubviews.count if count > 0 { - contentStack.setCustomSpacing(config.margin * 1.5, after: contentStack.arrangedSubviews[count-1]) + contentStack.setCustomSpacing(12, after: contentStack.arrangedSubviews[count-1]) } if count > 1 { - contentStack.setCustomSpacing(config.margin * 2, after: contentStack.arrangedSubviews[count-2]) + contentStack.setCustomSpacing(16, after: contentStack.arrangedSubviews[count-2]) } } else { // Fallback on earlier versions diff --git a/Sources/ProHUD/Sheet/SheetDefaultLayout.swift b/Sources/ProHUD/Sheet/SheetDefaultLayout.swift index 9c2ce45..70dc8f6 100644 --- a/Sources/ProHUD/Sheet/SheetDefaultLayout.swift +++ b/Sources/ProHUD/Sheet/SheetDefaultLayout.swift @@ -44,7 +44,7 @@ extension Sheet: DefaultLayout { loadContentMaskViewIfNeeded() // layout let maxWidth = config.cardMaxWidthByDefault - var width = UIScreen.main.bounds.width - config.edgeInset * 2 + var width = UIScreen.main.bounds.width - config.screenEdgeInset * 2 if width > maxWidth { // landscape iPhone or iPad width = maxWidth @@ -56,7 +56,7 @@ extension Sheet: DefaultLayout { make.centerX.equalToSuperview() if UIDevice.current.userInterfaceIdiom == .phone { if width < maxWidth { - make.bottom.equalToSuperview().inset(config.edgeInset) + make.bottom.equalToSuperview().inset(config.screenEdgeInset) } else { make.bottom.equalToSuperview().inset(screenSafeAreaInsets.bottom) } @@ -78,16 +78,20 @@ extension Sheet: DefaultLayout { if contentStack.superview == nil { contentView.addSubview(contentStack) contentStack.snp.remakeConstraints { make in + let safeArea: UIEdgeInsets if config.isFullScreen { - make.top.equalToSuperview().offset(screenSafeAreaInsets.top) + safeArea = screenSafeAreaInsets } else { - make.top.equalToSuperview().offset(config.padding * 2) + safeArea = .zero } - make.bottom.equalToSuperview().inset(config.padding * 2) + make.top.equalToSuperview().offset(safeArea.top + config.cardEdgeInsets.top) + make.bottom.equalToSuperview().inset(safeArea.bottom + config.cardEdgeInsets.bottom) if isPortrait { - make.left.right.equalToSuperview().inset(config.padding) + make.left.equalToSuperview().inset(safeArea.left + config.cardEdgeInsets.left) + make.right.equalToSuperview().inset(safeArea.right + config.cardEdgeInsets.right) } else { - make.left.right.equalToSuperview().inset(config.padding * 2) + make.left.equalToSuperview().inset(safeArea.left + config.cardEdgeInsets.left * 2) + make.right.equalToSuperview().inset(safeArea.right + config.cardEdgeInsets.right * 2) } } } diff --git a/Sources/ProHUD/Sheet/SheetManager.swift b/Sources/ProHUD/Sheet/SheetManager.swift index 2c6fd71..585b3bf 100644 --- a/Sources/ProHUD/Sheet/SheetManager.swift +++ b/Sources/ProHUD/Sheet/SheetManager.swift @@ -28,7 +28,7 @@ public extension Sheet { static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ sheet: Sheet) -> Void, onExists: ((_ sheet: Sheet) -> Void)? = nil) { let id = identifier ?? (file + "#\(line)") if let vc = find(identifier: id).last { - onExists?(vc) + vc.update(handler: onExists ?? handler) } else { Sheet { sheet in sheet.identifier = id @@ -86,7 +86,7 @@ extension Sheet { func _translateOut() { backgroundView.alpha = 0 - contentView.transform = .init(translationX: 0, y: view.frame.size.height - contentView.frame.minY + config.margin) + contentView.transform = .init(translationX: 0, y: view.frame.size.height - contentView.frame.minY + config.screenEdgeInset) } } diff --git a/Sources/ProHUD/Toast/Toast.swift b/Sources/ProHUD/Toast/Toast.swift index eab521a..b6e5782 100644 --- a/Sources/ProHUD/Toast/Toast.swift +++ b/Sources/ProHUD/Toast/Toast.swift @@ -22,15 +22,17 @@ public class Toast: Controller { /// 内容容器(包括icon、textStack、actionStack) public lazy var contentStack: StackView = { let stack = StackView(axis: .vertical) - stack.spacing = config.margin * 2 + stack.spacing = 16 + config.customContentStack?(stack) return stack }() /// 信息容器(image+text) public lazy var infoStack: StackView = { let stack = StackView(axis: .horizontal) - stack.spacing = config.margin + stack.spacing = 8 stack.alignment = .top + config.customInfoStack?(stack) return stack }() @@ -39,13 +41,15 @@ public class Toast: Controller { let stack = StackView(axis: .vertical) stack.spacing = config.lineSpace stack.distribution = .equalSpacing + config.customTextStack?(stack) return stack }() /// 按钮容器 public lazy var actionStack: StackView = { let stack = StackView(axis: .horizontal) - stack.spacing = config.margin + stack.spacing = 8 + config.customActionStack?(stack) return stack }() diff --git a/Sources/ProHUD/Toast/ToastButton.swift b/Sources/ProHUD/Toast/ToastButton.swift index 3602241..523d7b1 100644 --- a/Sources/ProHUD/Toast/ToastButton.swift +++ b/Sources/ProHUD/Toast/ToastButton.swift @@ -15,6 +15,7 @@ public class ToastButton: Button { public override func update(config: ProHUD.Configuration, action: Action) { titleLabel?.font = .boldSystemFont(ofSize: 15) + layer.cornerRadiusWithContinuous = 8 super.update(config: config, action: action) } diff --git a/Sources/ProHUD/Toast/ToastConfiguration.swift b/Sources/ProHUD/Toast/ToastConfiguration.swift index f661b6d..cffdc10 100644 --- a/Sources/ProHUD/Toast/ToastConfiguration.swift +++ b/Sources/ProHUD/Toast/ToastConfiguration.swift @@ -11,6 +11,13 @@ public extension Toast { class Configuration: ProHUD.Configuration { + /// 元素与元素之间的距离 + public var margin = CGFloat(8) + + var customInfoStack: ((_ stack: StackView) -> Void)? + public func customInfoStack(handler: @escaping (_ stack: StackView) -> Void) { + customInfoStack = handler + } /// 行间距 public var lineSpace = CGFloat(4) diff --git a/Sources/ProHUD/Toast/ToastDefaultLayout.swift b/Sources/ProHUD/Toast/ToastDefaultLayout.swift index 81bf152..67ee65d 100644 --- a/Sources/ProHUD/Toast/ToastDefaultLayout.swift +++ b/Sources/ProHUD/Toast/ToastDefaultLayout.swift @@ -96,8 +96,11 @@ extension Toast: DefaultLayout { // stacks if contentStack.superview != contentView { contentView.addSubview(contentStack) - contentStack.snp.remakeConstraints { (mk) in - mk.edges.equalToSuperview().inset(config.padding) + contentStack.snp.remakeConstraints { make in + make.top.equalToSuperview().inset(config.cardEdgeInsets.top) + make.left.equalToSuperview().inset(config.cardEdgeInsets.left) + make.bottom.equalToSuperview().inset(config.cardEdgeInsets.bottom) + make.right.equalToSuperview().inset(config.cardEdgeInsets.right) } } contentStack.insertArrangedSubview(infoStack, at: 0) diff --git a/Sources/ProHUD/Toast/ToastManager.swift b/Sources/ProHUD/Toast/ToastManager.swift index 2e4a804..569d860 100644 --- a/Sources/ProHUD/Toast/ToastManager.swift +++ b/Sources/ProHUD/Toast/ToastManager.swift @@ -28,7 +28,7 @@ public extension Toast { static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ toast: Toast) -> Void, onExists: ((_ toast: Toast) -> Void)? = nil) { let id = identifier ?? (file + "#\(line)") if let vc = find(identifier: id).last { - onExists?(vc) + vc.update(handler: onExists ?? handler) } else { Toast { toast in toast.identifier = id diff --git a/Sources/ProHUD/Toast/ToastWindow.swift b/Sources/ProHUD/Toast/ToastWindow.swift index be3a42d..fa4cdf2 100644 --- a/Sources/ProHUD/Toast/ToastWindow.swift +++ b/Sources/ProHUD/Toast/ToastWindow.swift @@ -50,7 +50,7 @@ class ToastWindow: Window { } let config = toast.config // frame - let width = CGFloat.minimum(UIScreen.main.bounds.width - 2*config.margin, config.cardMaxWidthByDefault) + let width = CGFloat.minimum(UIScreen.main.bounds.width - config.cardEdgeInsets.left - config.cardEdgeInsets.right, config.cardMaxWidthByDefault) toast.view.frame.size = CGSize(width: width, height: config.cardMaxHeightByDefault) toast.titleLabel.sizeToFit() toast.bodyLabel.sizeToFit() @@ -164,7 +164,7 @@ fileprivate extension Toast { height = CGFloat.maximum(v.frame.maxY, height) } // 上下边间距 - height += 2 * config.padding + height += config.cardEdgeInsets.top + config.cardEdgeInsets.bottom return height } }