From 7c4361637c4b7f69521c5a7f2a999c77f9f4c51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=BA=E6=9D=B0?= Date: Fri, 2 Jun 2017 11:54:48 +0800 Subject: [PATCH] adjust the size of label if text is too long --- SwiftNotice.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SwiftNotice.swift b/SwiftNotice.swift index 5fc875c..96cc599 100644 --- a/SwiftNotice.swift +++ b/SwiftNotice.swift @@ -224,7 +224,8 @@ class SwiftNotice: NSObject { label.font = UIFont.systemFont(ofSize: 13) label.textAlignment = NSTextAlignment.center label.textColor = UIColor.white - label.sizeToFit() + let size = label.sizeThatFits(CGSize(width: UIScreen.main.bounds.width-82, height: CGFloat.greatestFiniteMagnitude)) + label.bounds = CGRect(x: 0, y: 0, width: size.width, height: size.height) mainView.addSubview(label) let superFrame = CGRect(x: 0, y: 0, width: label.frame.width + 50 , height: label.frame.height + 30)