From 3afa04d2a3b6583dc483885c1304f430a9a4504e Mon Sep 17 00:00:00 2001 From: eternaljust Date: Sun, 8 Oct 2023 11:17:24 +0800 Subject: [PATCH] Add support for set text label constraint size to adjust the maximum display width of text --- Sources/IHProgressHUD/IHProgressHUD.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/IHProgressHUD/IHProgressHUD.swift b/Sources/IHProgressHUD/IHProgressHUD.swift index 3b5a95a..b579cfd 100755 --- a/Sources/IHProgressHUD/IHProgressHUD.swift +++ b/Sources/IHProgressHUD/IHProgressHUD.swift @@ -52,6 +52,7 @@ public class IHProgressHUD : UIView { private var defaultMaskType = IHProgressHUDMaskType.none private var defaultAnimationType = IHProgressHUDAnimationType.flat private var containerView: UIView? + private var labelConstraintSize = CGSize(width: 200.0, height: 300.0) private var minimumSize = CGSize(width: 50, height: 50) private var ringThickness: CGFloat = 2.0 private var ringRadius: CGFloat = 18.0 @@ -783,9 +784,8 @@ public class IHProgressHUD : UIView { var labelWidth: CGFloat = 0.0 if getStatusLabel().text != nil { - let constraintSize = CGSize(width: 200.0, height: 300.0) labelRect = getStatusLabel().text?.boundingRect( - with: constraintSize, + with: labelConstraintSize, options: [.usesFontLeading, .truncatesLastVisibleLine, .usesLineFragmentOrigin], attributes: [NSAttributedString.Key.font: getStatusLabel().font ?? UIFont.systemFont(ofSize: 15)], context: nil) ?? CGRect.zero @@ -1175,6 +1175,10 @@ extension IHProgressHUD { sharedView.containerView = containerView } // default is window level + public class func set(labelConstraintSize size: CGSize) { + sharedView.labelConstraintSize = size + } // default is 200x300 pt + public class func set(minimumSize: CGSize) { sharedView.minimumSize = minimumSize } // default is CGSizeZero, can be used to avoid resizing for a larger message