Skip to content

Commit

Permalink
make size of notice fit text in noticeOnlyText function
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlui committed May 24, 2015
1 parent d1780b5 commit 2677400
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
19 changes: 14 additions & 5 deletions SwiftNotice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.
8 changes: 1 addition & 7 deletions SwiftNoticeExample/SwiftNoticeExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2677400

Please sign in to comment.