diff --git a/SwiftNotice.swift b/SwiftNotice.swift index 92c625c..5b9b4e9 100644 --- a/SwiftNotice.swift +++ b/SwiftNotice.swift @@ -60,7 +60,9 @@ class SwiftNotice: NSObject { static let rv = UIApplication.sharedApplication().keyWindow?.subviews.first as! UIView static func clear() { - windows.removeAll(keepCapacity: false) + for i in windows { + i.hidden = true + } } static func noticeOnSatusBar(text: String, autoClear: Bool) { @@ -105,19 +107,26 @@ class SwiftNotice: NSObject { windows.append(window) } static func showText(text: String) { - let frame = CGRectMake(0, 0, 200, 60) - let window = UIWindow(frame: frame) - let mainView = UIView(frame: frame) + let window = UIWindow() + let mainView = UIView() mainView.layer.cornerRadius = 12 mainView.backgroundColor = UIColor(red:0, green:0, blue:0, alpha: 0.8) - let label = UILabel(frame: frame) + let label = UILabel() label.text = text + label.numberOfLines = 0 label.font = UIFont.systemFontOfSize(13) label.textAlignment = NSTextAlignment.Center label.textColor = UIColor.whiteColor() + label.sizeToFit() mainView.addSubview(label) + let superFrame = CGRectMake(0, 0, label.frame.width + 50 , label.frame.height + 30) + window.frame = superFrame + mainView.frame = superFrame + + label.center = mainView.center + window.windowLevel = UIWindowLevelAlert window.center = rv.center window.hidden = false diff --git a/SwiftNoticeExample/SwiftNoticeExample.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate b/SwiftNoticeExample/SwiftNoticeExample.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate index c656ca4..1efe2b7 100644 Binary files a/SwiftNoticeExample/SwiftNoticeExample.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate and b/SwiftNoticeExample/SwiftNoticeExample.xcodeproj/project.xcworkspace/xcuserdata/dren_a.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/SwiftNoticeExample/SwiftNoticeExample/ViewController.swift b/SwiftNoticeExample/SwiftNoticeExample/ViewController.swift index f598d2b..6888f67 100644 --- a/SwiftNoticeExample/SwiftNoticeExample/ViewController.swift +++ b/SwiftNoticeExample/SwiftNoticeExample/ViewController.swift @@ -28,21 +28,15 @@ class ViewController: UIViewController { } @IBAction func noticeSuccess(sender: AnyObject) { self.successNotice("Success!") - self.successNotice("Success!", autoClear: false) - self.notice("Success!", type: NoticeType.success, autoClear: true) } @IBAction func noticeError(sender: AnyObject) { self.errorNotice("Error!") - self.errorNotice("Error!", autoClear: false) - self.notice("Error!", type: NoticeType.error, autoClear: true) } @IBAction func noticeInfo(sender: AnyObject) { self.infoNotice("Info") - self.infoNotice("Info", autoClear: false) - self.notice("Info", type: NoticeType.info, autoClear: true) } @IBAction func text(sender: AnyObject) { - self.noticeOnlyText("Only Text") + self.noticeOnlyText("Only Text Only Text Only Text Only \nText Only Text Only Text Only\n Text Only Text Only Text ") } @IBAction func clear(sender: AnyObject) { self.clearAllNotice()