├── DPNotify └── DPNotify.swift ├── DemoDPNotify.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── DemoDPNotify.xccheckout │ └── xcuserdata │ │ └── baophan.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── baophan.xcuserdatad │ └── xcschemes │ ├── DemoDPNotify.xcscheme │ └── xcschememanagement.plist ├── DemoDPNotify ├── AppDelegate.swift ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── DPNotify │ └── DPNotify.swift ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist └── TableViewController.swift ├── DemoDPNotifyTests ├── DemoDPNotifyTests.swift └── Info.plist ├── README.md └── demo.gif /DPNotify/DPNotify.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DPNotify.swift 3 | // DemoDPNotify 4 | // 5 | // Created by @baophan94 on 6/26/15. 6 | // Contact: www.dinophan.com - baophan94@icloud.com 7 | // Copyright (c) 2015 @baophan94. All rights reserved. 8 | // 9 | 10 | import UIKit 11 | 12 | enum DPNOTIFYTYPE { 13 | case DEFAULT 14 | case DANGER 15 | case WARNING 16 | case SUCCESS 17 | case DISABLED 18 | } 19 | 20 | class DPNotify: NSObject { 21 | 22 | static let sharedNotify = DPNotify() 23 | 24 | // Customize banner 25 | var bannerBackgroundColor: UIColor! 26 | var bannerForegroundColor: UIColor! 27 | var tapToDismiss: Bool! 28 | var delayTimer: NSTimeInterval! 29 | var bannerType: DPNOTIFYTYPE! 30 | 31 | // Customize text 32 | var notifyTitle: String! 33 | var notifyTitleFont: UIFont! 34 | 35 | // DPNotify Banner 36 | var bannerView: UIView! 37 | var tapGesture: UITapGestureRecognizer? 38 | 39 | 40 | 41 | func showNotifyInView(inView: UIView, title: String, dismissOnTap: Bool) { 42 | 43 | if self.bannerView != nil { 44 | if self.tapGesture != nil { 45 | self.bannerView.removeGestureRecognizer(self.tapGesture!) 46 | self.tapGesture = nil 47 | } 48 | self.bannerView.removeFromSuperview() 49 | self.bannerView = nil 50 | } 51 | 52 | self.applyDefaultType() 53 | 54 | self.notifyTitle = title 55 | self.tapToDismiss = dismissOnTap 56 | 57 | let containerFrame: CGRect = inView.frame 58 | self.bannerView = UIView() 59 | self.bannerView.backgroundColor = self.bannerBackgroundColor 60 | 61 | var calculationView: UITextView = UITextView() 62 | calculationView.attributedText = NSAttributedString(string: self.notifyTitle, attributes: 63 | [ 64 | NSFontAttributeName: notifyTitleFont 65 | ]) 66 | let size: CGSize = calculationView.sizeThatFits( 67 | CGSizeMake(containerFrame.width - 48, CGFloat(FLT_MAX))) 68 | let titleView = UITextView( 69 | frame: CGRectMake(8, 0, containerFrame.width - 48, size.height)) 70 | titleView.text = self.notifyTitle 71 | titleView.font = self.notifyTitleFont 72 | titleView.alpha = 0 73 | titleView.textColor = UIColor.whiteColor() 74 | titleView.backgroundColor = UIColor.clearColor() 75 | titleView.editable = false 76 | titleView.selectable = false 77 | self.bannerView.addSubview(titleView) 78 | self.bannerView.alpha = 0 79 | self.bannerView.frame = CGRectMake(0, -titleView.frame.size.height, containerFrame.width, titleView.frame.size.height) 80 | inView.addSubview(self.bannerView) 81 | 82 | addTapToDismissGesture() 83 | 84 | UIView.animateWithDuration(0.2, animations: { () -> Void in 85 | self.bannerView.alpha = 1 86 | titleView.alpha = 1 87 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height + 5) 88 | }) { (Bool) -> Void in 89 | if self.bannerView != nil { 90 | UIView.animateWithDuration(0.2, animations: { () -> Void in 91 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height) 92 | }, completion: { (Bool) -> Void in 93 | 94 | }) 95 | } 96 | } 97 | } 98 | 99 | func showNotifyInView(inView: UIView, title: String, dismissOnTap: Bool, notifyType: DPNOTIFYTYPE) { 100 | 101 | if self.bannerView != nil { 102 | if self.tapGesture != nil { 103 | self.bannerView.removeGestureRecognizer(self.tapGesture!) 104 | self.tapGesture = nil 105 | } 106 | self.bannerView.removeFromSuperview() 107 | self.bannerView = nil 108 | } 109 | 110 | switch notifyType { 111 | case DPNOTIFYTYPE.DEFAULT: self.applyDefaultType() 112 | case DPNOTIFYTYPE.DANGER: self.applyDangerType() 113 | case DPNOTIFYTYPE.DISABLED: self.applyDisabledType() 114 | case DPNOTIFYTYPE.SUCCESS: self.applySuccessType() 115 | case DPNOTIFYTYPE.WARNING: self.applyWarningType() 116 | default: self.applyDefaultType() 117 | } 118 | 119 | self.notifyTitle = title 120 | self.tapToDismiss = dismissOnTap 121 | 122 | let containerFrame: CGRect = inView.frame 123 | self.bannerView = UIView() 124 | self.bannerView.backgroundColor = self.bannerBackgroundColor 125 | 126 | var calculationView: UITextView = UITextView() 127 | calculationView.attributedText = NSAttributedString(string: self.notifyTitle, attributes: 128 | [ 129 | NSFontAttributeName: notifyTitleFont 130 | ]) 131 | let size: CGSize = calculationView.sizeThatFits( 132 | CGSizeMake(containerFrame.width - 48, CGFloat(FLT_MAX))) 133 | let titleView = UITextView( 134 | frame: CGRectMake(8, 0, containerFrame.width - 48, size.height)) 135 | titleView.text = self.notifyTitle 136 | titleView.font = self.notifyTitleFont 137 | titleView.alpha = 0 138 | titleView.textColor = UIColor.whiteColor() 139 | titleView.backgroundColor = UIColor.clearColor() 140 | titleView.editable = false 141 | titleView.selectable = false 142 | self.bannerView.addSubview(titleView) 143 | self.bannerView.alpha = 0 144 | self.bannerView.frame = CGRectMake(0, -titleView.frame.size.height, containerFrame.width, titleView.frame.size.height) 145 | inView.addSubview(self.bannerView) 146 | 147 | if dismissOnTap == true { 148 | addTapToDismissGesture() 149 | } 150 | 151 | UIView.animateWithDuration(0.2, animations: { () -> Void in 152 | self.bannerView.alpha = 1 153 | titleView.alpha = 1 154 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height + 5) 155 | }) { (Bool) -> Void in 156 | if self.bannerView != nil { 157 | UIView.animateWithDuration(0.2, animations: { () -> Void in 158 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height) 159 | }, completion: { (Bool) -> Void in 160 | 161 | }) 162 | } 163 | } 164 | } 165 | 166 | func showNotifyInView(inView: UIView, title: String, dismissOnTap: Bool, notifyType: DPNOTIFYTYPE, delay: NSTimeInterval) { 167 | 168 | if self.bannerView != nil { 169 | if self.tapGesture != nil { 170 | self.bannerView.removeGestureRecognizer(self.tapGesture!) 171 | self.tapGesture = nil 172 | } 173 | self.bannerView.removeFromSuperview() 174 | self.bannerView = nil 175 | } 176 | 177 | switch notifyType { 178 | case DPNOTIFYTYPE.DEFAULT: self.applyDefaultType() 179 | case DPNOTIFYTYPE.DANGER: self.applyDangerType() 180 | case DPNOTIFYTYPE.DISABLED: self.applyDisabledType() 181 | case DPNOTIFYTYPE.SUCCESS: self.applySuccessType() 182 | case DPNOTIFYTYPE.WARNING: self.applyWarningType() 183 | default: self.applyDefaultType() 184 | } 185 | 186 | self.delayTimer = delay 187 | 188 | self.notifyTitle = title 189 | self.tapToDismiss = dismissOnTap 190 | 191 | let containerFrame: CGRect = inView.frame 192 | self.bannerView = UIView() 193 | self.bannerView.backgroundColor = self.bannerBackgroundColor 194 | 195 | var calculationView: UITextView = UITextView() 196 | calculationView.attributedText = NSAttributedString(string: self.notifyTitle, attributes: 197 | [ 198 | NSFontAttributeName: notifyTitleFont 199 | ]) 200 | let size: CGSize = calculationView.sizeThatFits( 201 | CGSizeMake(containerFrame.width - 48, CGFloat(FLT_MAX))) 202 | let titleView = UITextView( 203 | frame: CGRectMake(8, 0, containerFrame.width - 48, size.height)) 204 | titleView.text = self.notifyTitle 205 | titleView.font = self.notifyTitleFont 206 | titleView.alpha = 0 207 | titleView.textColor = UIColor.whiteColor() 208 | titleView.backgroundColor = UIColor.clearColor() 209 | titleView.editable = false 210 | titleView.selectable = false 211 | self.bannerView.addSubview(titleView) 212 | self.bannerView.alpha = 0 213 | self.bannerView.frame = CGRectMake(0, -titleView.frame.size.height, containerFrame.width, titleView.frame.size.height) 214 | inView.addSubview(self.bannerView) 215 | 216 | if dismissOnTap == true { 217 | addTapToDismissGesture() 218 | } 219 | 220 | UIView.animateWithDuration(0.2, animations: { () -> Void in 221 | self.bannerView.alpha = 1 222 | titleView.alpha = 1 223 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height + 5) 224 | }) { (Bool) -> Void in 225 | if self.bannerView != nil { 226 | UIView.animateWithDuration(0.2, animations: { () -> Void in 227 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height) 228 | }, completion: { (Bool) -> Void in 229 | UIView.animateWithDuration(self.delayTimer, animations: { () -> Void in 230 | if self.bannerView != nil { 231 | self.bannerView.alpha = 0.8 232 | } 233 | }, completion: { (Bool) -> Void in 234 | self.dismissNotify() 235 | }) 236 | }) 237 | } 238 | } 239 | } 240 | 241 | func dismissNotify() { 242 | if self.bannerView != nil { 243 | let curFrame = self.bannerView.frame 244 | UIView.animateWithDuration(0.2, animations: { () -> Void in 245 | self.bannerView.alpha = 0 246 | self.bannerView.frame = CGRectMake(0, -curFrame.height, curFrame.width, curFrame.height) 247 | }, completion: { (Bool) -> Void in 248 | if self.bannerView != nil { 249 | self.bannerView = nil 250 | } 251 | }) 252 | } 253 | } 254 | 255 | func dismissNotify(completion: () -> Void) { 256 | if self.bannerView != nil { 257 | let curFrame = self.bannerView.frame 258 | UIView.animateWithDuration(0.2, animations: { () -> Void in 259 | self.bannerView.alpha = 0 260 | self.bannerView.frame = CGRectMake(0, -curFrame.height, curFrame.width, curFrame.height) 261 | }, completion: { (Bool) -> Void in 262 | if self.bannerView != nil { 263 | self.bannerView = nil 264 | } 265 | completion() 266 | }) 267 | } 268 | } 269 | 270 | func addTapToDismissGesture() { 271 | if self.tapGesture != nil { 272 | self.tapGesture = nil 273 | } 274 | if tapToDismiss == true { 275 | self.tapGesture = UITapGestureRecognizer(target: self, action: "dismissNotify") 276 | self.bannerView.addGestureRecognizer(tapGesture!) 277 | } 278 | } 279 | 280 | // MARK: Banner Type 281 | func applyDefaultType() { 282 | notifyTitle = "" 283 | notifyTitleFont = UIFont.systemFontOfSize(17) 284 | bannerBackgroundColor = color(0x9E9E9E, alpha: 1.0) 285 | bannerForegroundColor = UIColor.whiteColor() 286 | delayTimer = 0 287 | } 288 | 289 | func applyDangerType() { 290 | notifyTitle = "" 291 | notifyTitleFont = UIFont.systemFontOfSize(17) 292 | bannerBackgroundColor = color(0xE53935, alpha: 1.0) 293 | bannerForegroundColor = UIColor.whiteColor() 294 | delayTimer = 0 295 | } 296 | 297 | func applyWarningType() { 298 | notifyTitle = "" 299 | notifyTitleFont = UIFont.systemFontOfSize(17) 300 | bannerBackgroundColor = color(0xFF8F00, alpha: 1.0) 301 | bannerForegroundColor = UIColor.whiteColor() 302 | delayTimer = 0 303 | } 304 | 305 | func applySuccessType() { 306 | notifyTitle = "" 307 | notifyTitleFont = UIFont.systemFontOfSize(17) 308 | bannerBackgroundColor = color(0x03A9F4, alpha: 1.0) 309 | bannerForegroundColor = UIColor.whiteColor() 310 | delayTimer = 0 311 | } 312 | 313 | func applyDisabledType() { 314 | notifyTitle = "" 315 | notifyTitleFont = UIFont.systemFontOfSize(17) 316 | bannerBackgroundColor = color(0x000000, alpha: 1.0) 317 | bannerForegroundColor = UIColor.whiteColor() 318 | delayTimer = 0 319 | } 320 | 321 | func color(hex: Int, alpha: CGFloat = 1.0) -> UIColor { 322 | let red = CGFloat((hex & 0xFF0000) >> 16) / 255.0 323 | let green = CGFloat((hex & 0xFF00) >> 8) / 255.0 324 | let blue = CGFloat((hex & 0xFF)) / 255.0 325 | return UIColor(red: red, green: green, blue: blue, alpha: alpha) 326 | } 327 | 328 | } 329 | -------------------------------------------------------------------------------- /DemoDPNotify.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8D2C2D4C1B3D8E0000FD3DE9 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D2C2D4B1B3D8E0000FD3DE9 /* TableViewController.swift */; }; 11 | 8D746C6D1B3D0F3800372FA0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D746C6C1B3D0F3800372FA0 /* AppDelegate.swift */; }; 12 | 8D746C721B3D0F3800372FA0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D746C701B3D0F3800372FA0 /* Main.storyboard */; }; 13 | 8D746C741B3D0F3800372FA0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8D746C731B3D0F3800372FA0 /* Images.xcassets */; }; 14 | 8D746C771B3D0F3800372FA0 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8D746C751B3D0F3800372FA0 /* LaunchScreen.xib */; }; 15 | 8D746C831B3D0F3900372FA0 /* DemoDPNotifyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D746C821B3D0F3900372FA0 /* DemoDPNotifyTests.swift */; }; 16 | 8DAA9C3A1B3DC29F00FEB971 /* DPNotify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DAA9C391B3DC29F00FEB971 /* DPNotify.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | 8D746C7D1B3D0F3900372FA0 /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = 8D746C5F1B3D0F3800372FA0 /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = 8D746C661B3D0F3800372FA0; 25 | remoteInfo = DemoDPNotify; 26 | }; 27 | /* End PBXContainerItemProxy section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 8D2C2D4B1B3D8E0000FD3DE9 /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; 31 | 8D746C671B3D0F3800372FA0 /* DemoDPNotify.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DemoDPNotify.app; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | 8D746C6B1B3D0F3800372FA0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | 8D746C6C1B3D0F3800372FA0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 34 | 8D746C711B3D0F3800372FA0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 35 | 8D746C731B3D0F3800372FA0 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 36 | 8D746C761B3D0F3800372FA0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 37 | 8D746C7C1B3D0F3900372FA0 /* DemoDPNotifyTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DemoDPNotifyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | 8D746C811B3D0F3900372FA0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 39 | 8D746C821B3D0F3900372FA0 /* DemoDPNotifyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoDPNotifyTests.swift; sourceTree = ""; }; 40 | 8DAA9C391B3DC29F00FEB971 /* DPNotify.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DPNotify.swift; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | 8D746C641B3D0F3800372FA0 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | 8D746C791B3D0F3900372FA0 /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | /* End PBXFrameworksBuildPhase section */ 59 | 60 | /* Begin PBXGroup section */ 61 | 8D746C5E1B3D0F3800372FA0 = { 62 | isa = PBXGroup; 63 | children = ( 64 | 8D746C691B3D0F3800372FA0 /* DemoDPNotify */, 65 | 8D746C7F1B3D0F3900372FA0 /* DemoDPNotifyTests */, 66 | 8D746C681B3D0F3800372FA0 /* Products */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | 8D746C681B3D0F3800372FA0 /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 8D746C671B3D0F3800372FA0 /* DemoDPNotify.app */, 74 | 8D746C7C1B3D0F3900372FA0 /* DemoDPNotifyTests.xctest */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | 8D746C691B3D0F3800372FA0 /* DemoDPNotify */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 8DAA9C381B3DC29F00FEB971 /* DPNotify */, 83 | 8D746C6C1B3D0F3800372FA0 /* AppDelegate.swift */, 84 | 8D2C2D4B1B3D8E0000FD3DE9 /* TableViewController.swift */, 85 | 8D746C701B3D0F3800372FA0 /* Main.storyboard */, 86 | 8D746C731B3D0F3800372FA0 /* Images.xcassets */, 87 | 8D746C751B3D0F3800372FA0 /* LaunchScreen.xib */, 88 | 8D746C6A1B3D0F3800372FA0 /* Supporting Files */, 89 | ); 90 | path = DemoDPNotify; 91 | sourceTree = ""; 92 | }; 93 | 8D746C6A1B3D0F3800372FA0 /* Supporting Files */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 8D746C6B1B3D0F3800372FA0 /* Info.plist */, 97 | ); 98 | name = "Supporting Files"; 99 | sourceTree = ""; 100 | }; 101 | 8D746C7F1B3D0F3900372FA0 /* DemoDPNotifyTests */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 8D746C821B3D0F3900372FA0 /* DemoDPNotifyTests.swift */, 105 | 8D746C801B3D0F3900372FA0 /* Supporting Files */, 106 | ); 107 | path = DemoDPNotifyTests; 108 | sourceTree = ""; 109 | }; 110 | 8D746C801B3D0F3900372FA0 /* Supporting Files */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 8D746C811B3D0F3900372FA0 /* Info.plist */, 114 | ); 115 | name = "Supporting Files"; 116 | sourceTree = ""; 117 | }; 118 | 8DAA9C381B3DC29F00FEB971 /* DPNotify */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 8DAA9C391B3DC29F00FEB971 /* DPNotify.swift */, 122 | ); 123 | path = DPNotify; 124 | sourceTree = ""; 125 | }; 126 | /* End PBXGroup section */ 127 | 128 | /* Begin PBXNativeTarget section */ 129 | 8D746C661B3D0F3800372FA0 /* DemoDPNotify */ = { 130 | isa = PBXNativeTarget; 131 | buildConfigurationList = 8D746C861B3D0F3900372FA0 /* Build configuration list for PBXNativeTarget "DemoDPNotify" */; 132 | buildPhases = ( 133 | 8D746C631B3D0F3800372FA0 /* Sources */, 134 | 8D746C641B3D0F3800372FA0 /* Frameworks */, 135 | 8D746C651B3D0F3800372FA0 /* Resources */, 136 | ); 137 | buildRules = ( 138 | ); 139 | dependencies = ( 140 | ); 141 | name = DemoDPNotify; 142 | productName = DemoDPNotify; 143 | productReference = 8D746C671B3D0F3800372FA0 /* DemoDPNotify.app */; 144 | productType = "com.apple.product-type.application"; 145 | }; 146 | 8D746C7B1B3D0F3900372FA0 /* DemoDPNotifyTests */ = { 147 | isa = PBXNativeTarget; 148 | buildConfigurationList = 8D746C891B3D0F3900372FA0 /* Build configuration list for PBXNativeTarget "DemoDPNotifyTests" */; 149 | buildPhases = ( 150 | 8D746C781B3D0F3900372FA0 /* Sources */, 151 | 8D746C791B3D0F3900372FA0 /* Frameworks */, 152 | 8D746C7A1B3D0F3900372FA0 /* Resources */, 153 | ); 154 | buildRules = ( 155 | ); 156 | dependencies = ( 157 | 8D746C7E1B3D0F3900372FA0 /* PBXTargetDependency */, 158 | ); 159 | name = DemoDPNotifyTests; 160 | productName = DemoDPNotifyTests; 161 | productReference = 8D746C7C1B3D0F3900372FA0 /* DemoDPNotifyTests.xctest */; 162 | productType = "com.apple.product-type.bundle.unit-test"; 163 | }; 164 | /* End PBXNativeTarget section */ 165 | 166 | /* Begin PBXProject section */ 167 | 8D746C5F1B3D0F3800372FA0 /* Project object */ = { 168 | isa = PBXProject; 169 | attributes = { 170 | LastUpgradeCheck = 0630; 171 | ORGANIZATIONNAME = "@baophan94"; 172 | TargetAttributes = { 173 | 8D746C661B3D0F3800372FA0 = { 174 | CreatedOnToolsVersion = 6.3.2; 175 | }; 176 | 8D746C7B1B3D0F3900372FA0 = { 177 | CreatedOnToolsVersion = 6.3.2; 178 | TestTargetID = 8D746C661B3D0F3800372FA0; 179 | }; 180 | }; 181 | }; 182 | buildConfigurationList = 8D746C621B3D0F3800372FA0 /* Build configuration list for PBXProject "DemoDPNotify" */; 183 | compatibilityVersion = "Xcode 3.2"; 184 | developmentRegion = English; 185 | hasScannedForEncodings = 0; 186 | knownRegions = ( 187 | en, 188 | Base, 189 | ); 190 | mainGroup = 8D746C5E1B3D0F3800372FA0; 191 | productRefGroup = 8D746C681B3D0F3800372FA0 /* Products */; 192 | projectDirPath = ""; 193 | projectRoot = ""; 194 | targets = ( 195 | 8D746C661B3D0F3800372FA0 /* DemoDPNotify */, 196 | 8D746C7B1B3D0F3900372FA0 /* DemoDPNotifyTests */, 197 | ); 198 | }; 199 | /* End PBXProject section */ 200 | 201 | /* Begin PBXResourcesBuildPhase section */ 202 | 8D746C651B3D0F3800372FA0 /* Resources */ = { 203 | isa = PBXResourcesBuildPhase; 204 | buildActionMask = 2147483647; 205 | files = ( 206 | 8D746C721B3D0F3800372FA0 /* Main.storyboard in Resources */, 207 | 8D746C771B3D0F3800372FA0 /* LaunchScreen.xib in Resources */, 208 | 8D746C741B3D0F3800372FA0 /* Images.xcassets in Resources */, 209 | ); 210 | runOnlyForDeploymentPostprocessing = 0; 211 | }; 212 | 8D746C7A1B3D0F3900372FA0 /* Resources */ = { 213 | isa = PBXResourcesBuildPhase; 214 | buildActionMask = 2147483647; 215 | files = ( 216 | ); 217 | runOnlyForDeploymentPostprocessing = 0; 218 | }; 219 | /* End PBXResourcesBuildPhase section */ 220 | 221 | /* Begin PBXSourcesBuildPhase section */ 222 | 8D746C631B3D0F3800372FA0 /* Sources */ = { 223 | isa = PBXSourcesBuildPhase; 224 | buildActionMask = 2147483647; 225 | files = ( 226 | 8D2C2D4C1B3D8E0000FD3DE9 /* TableViewController.swift in Sources */, 227 | 8DAA9C3A1B3DC29F00FEB971 /* DPNotify.swift in Sources */, 228 | 8D746C6D1B3D0F3800372FA0 /* AppDelegate.swift in Sources */, 229 | ); 230 | runOnlyForDeploymentPostprocessing = 0; 231 | }; 232 | 8D746C781B3D0F3900372FA0 /* Sources */ = { 233 | isa = PBXSourcesBuildPhase; 234 | buildActionMask = 2147483647; 235 | files = ( 236 | 8D746C831B3D0F3900372FA0 /* DemoDPNotifyTests.swift in Sources */, 237 | ); 238 | runOnlyForDeploymentPostprocessing = 0; 239 | }; 240 | /* End PBXSourcesBuildPhase section */ 241 | 242 | /* Begin PBXTargetDependency section */ 243 | 8D746C7E1B3D0F3900372FA0 /* PBXTargetDependency */ = { 244 | isa = PBXTargetDependency; 245 | target = 8D746C661B3D0F3800372FA0 /* DemoDPNotify */; 246 | targetProxy = 8D746C7D1B3D0F3900372FA0 /* PBXContainerItemProxy */; 247 | }; 248 | /* End PBXTargetDependency section */ 249 | 250 | /* Begin PBXVariantGroup section */ 251 | 8D746C701B3D0F3800372FA0 /* Main.storyboard */ = { 252 | isa = PBXVariantGroup; 253 | children = ( 254 | 8D746C711B3D0F3800372FA0 /* Base */, 255 | ); 256 | name = Main.storyboard; 257 | sourceTree = ""; 258 | }; 259 | 8D746C751B3D0F3800372FA0 /* LaunchScreen.xib */ = { 260 | isa = PBXVariantGroup; 261 | children = ( 262 | 8D746C761B3D0F3800372FA0 /* Base */, 263 | ); 264 | name = LaunchScreen.xib; 265 | sourceTree = ""; 266 | }; 267 | /* End PBXVariantGroup section */ 268 | 269 | /* Begin XCBuildConfiguration section */ 270 | 8D746C841B3D0F3900372FA0 /* Debug */ = { 271 | isa = XCBuildConfiguration; 272 | buildSettings = { 273 | ALWAYS_SEARCH_USER_PATHS = NO; 274 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 275 | CLANG_CXX_LIBRARY = "libc++"; 276 | CLANG_ENABLE_MODULES = YES; 277 | CLANG_ENABLE_OBJC_ARC = YES; 278 | CLANG_WARN_BOOL_CONVERSION = YES; 279 | CLANG_WARN_CONSTANT_CONVERSION = YES; 280 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 281 | CLANG_WARN_EMPTY_BODY = YES; 282 | CLANG_WARN_ENUM_CONVERSION = YES; 283 | CLANG_WARN_INT_CONVERSION = YES; 284 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 285 | CLANG_WARN_UNREACHABLE_CODE = YES; 286 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 287 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 288 | COPY_PHASE_STRIP = NO; 289 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 290 | ENABLE_STRICT_OBJC_MSGSEND = YES; 291 | GCC_C_LANGUAGE_STANDARD = gnu99; 292 | GCC_DYNAMIC_NO_PIC = NO; 293 | GCC_NO_COMMON_BLOCKS = YES; 294 | GCC_OPTIMIZATION_LEVEL = 0; 295 | GCC_PREPROCESSOR_DEFINITIONS = ( 296 | "DEBUG=1", 297 | "$(inherited)", 298 | ); 299 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 300 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 301 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 302 | GCC_WARN_UNDECLARED_SELECTOR = YES; 303 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 304 | GCC_WARN_UNUSED_FUNCTION = YES; 305 | GCC_WARN_UNUSED_VARIABLE = YES; 306 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 307 | MTL_ENABLE_DEBUG_INFO = YES; 308 | ONLY_ACTIVE_ARCH = YES; 309 | SDKROOT = iphoneos; 310 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 311 | TARGETED_DEVICE_FAMILY = "1,2"; 312 | }; 313 | name = Debug; 314 | }; 315 | 8D746C851B3D0F3900372FA0 /* Release */ = { 316 | isa = XCBuildConfiguration; 317 | buildSettings = { 318 | ALWAYS_SEARCH_USER_PATHS = NO; 319 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 320 | CLANG_CXX_LIBRARY = "libc++"; 321 | CLANG_ENABLE_MODULES = YES; 322 | CLANG_ENABLE_OBJC_ARC = YES; 323 | CLANG_WARN_BOOL_CONVERSION = YES; 324 | CLANG_WARN_CONSTANT_CONVERSION = YES; 325 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 326 | CLANG_WARN_EMPTY_BODY = YES; 327 | CLANG_WARN_ENUM_CONVERSION = YES; 328 | CLANG_WARN_INT_CONVERSION = YES; 329 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 330 | CLANG_WARN_UNREACHABLE_CODE = YES; 331 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 332 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 333 | COPY_PHASE_STRIP = NO; 334 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 335 | ENABLE_NS_ASSERTIONS = NO; 336 | ENABLE_STRICT_OBJC_MSGSEND = YES; 337 | GCC_C_LANGUAGE_STANDARD = gnu99; 338 | GCC_NO_COMMON_BLOCKS = YES; 339 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 340 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 341 | GCC_WARN_UNDECLARED_SELECTOR = YES; 342 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 343 | GCC_WARN_UNUSED_FUNCTION = YES; 344 | GCC_WARN_UNUSED_VARIABLE = YES; 345 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 346 | MTL_ENABLE_DEBUG_INFO = NO; 347 | SDKROOT = iphoneos; 348 | TARGETED_DEVICE_FAMILY = "1,2"; 349 | VALIDATE_PRODUCT = YES; 350 | }; 351 | name = Release; 352 | }; 353 | 8D746C871B3D0F3900372FA0 /* Debug */ = { 354 | isa = XCBuildConfiguration; 355 | buildSettings = { 356 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 357 | INFOPLIST_FILE = DemoDPNotify/Info.plist; 358 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 359 | PRODUCT_NAME = "$(TARGET_NAME)"; 360 | }; 361 | name = Debug; 362 | }; 363 | 8D746C881B3D0F3900372FA0 /* Release */ = { 364 | isa = XCBuildConfiguration; 365 | buildSettings = { 366 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 367 | INFOPLIST_FILE = DemoDPNotify/Info.plist; 368 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 369 | PRODUCT_NAME = "$(TARGET_NAME)"; 370 | }; 371 | name = Release; 372 | }; 373 | 8D746C8A1B3D0F3900372FA0 /* Debug */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | BUNDLE_LOADER = "$(TEST_HOST)"; 377 | FRAMEWORK_SEARCH_PATHS = ( 378 | "$(SDKROOT)/Developer/Library/Frameworks", 379 | "$(inherited)", 380 | ); 381 | GCC_PREPROCESSOR_DEFINITIONS = ( 382 | "DEBUG=1", 383 | "$(inherited)", 384 | ); 385 | INFOPLIST_FILE = DemoDPNotifyTests/Info.plist; 386 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 387 | PRODUCT_NAME = "$(TARGET_NAME)"; 388 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DemoDPNotify.app/DemoDPNotify"; 389 | }; 390 | name = Debug; 391 | }; 392 | 8D746C8B1B3D0F3900372FA0 /* Release */ = { 393 | isa = XCBuildConfiguration; 394 | buildSettings = { 395 | BUNDLE_LOADER = "$(TEST_HOST)"; 396 | FRAMEWORK_SEARCH_PATHS = ( 397 | "$(SDKROOT)/Developer/Library/Frameworks", 398 | "$(inherited)", 399 | ); 400 | INFOPLIST_FILE = DemoDPNotifyTests/Info.plist; 401 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 402 | PRODUCT_NAME = "$(TARGET_NAME)"; 403 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DemoDPNotify.app/DemoDPNotify"; 404 | }; 405 | name = Release; 406 | }; 407 | /* End XCBuildConfiguration section */ 408 | 409 | /* Begin XCConfigurationList section */ 410 | 8D746C621B3D0F3800372FA0 /* Build configuration list for PBXProject "DemoDPNotify" */ = { 411 | isa = XCConfigurationList; 412 | buildConfigurations = ( 413 | 8D746C841B3D0F3900372FA0 /* Debug */, 414 | 8D746C851B3D0F3900372FA0 /* Release */, 415 | ); 416 | defaultConfigurationIsVisible = 0; 417 | defaultConfigurationName = Release; 418 | }; 419 | 8D746C861B3D0F3900372FA0 /* Build configuration list for PBXNativeTarget "DemoDPNotify" */ = { 420 | isa = XCConfigurationList; 421 | buildConfigurations = ( 422 | 8D746C871B3D0F3900372FA0 /* Debug */, 423 | 8D746C881B3D0F3900372FA0 /* Release */, 424 | ); 425 | defaultConfigurationIsVisible = 0; 426 | defaultConfigurationName = Release; 427 | }; 428 | 8D746C891B3D0F3900372FA0 /* Build configuration list for PBXNativeTarget "DemoDPNotifyTests" */ = { 429 | isa = XCConfigurationList; 430 | buildConfigurations = ( 431 | 8D746C8A1B3D0F3900372FA0 /* Debug */, 432 | 8D746C8B1B3D0F3900372FA0 /* Release */, 433 | ); 434 | defaultConfigurationIsVisible = 0; 435 | defaultConfigurationName = Release; 436 | }; 437 | /* End XCConfigurationList section */ 438 | }; 439 | rootObject = 8D746C5F1B3D0F3800372FA0 /* Project object */; 440 | } 441 | -------------------------------------------------------------------------------- /DemoDPNotify.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DemoDPNotify.xcodeproj/project.xcworkspace/xcshareddata/DemoDPNotify.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 6DB7F87C-E93B-473D-BF4D-59A919FD6FAD 9 | IDESourceControlProjectName 10 | DemoDPNotify 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 2C60C1996D007C9FD8D3D8C844008BFFB5028D28 14 | https://github.com/dphans/DPNotify.git 15 | 16 | IDESourceControlProjectPath 17 | DemoDPNotify.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 2C60C1996D007C9FD8D3D8C844008BFFB5028D28 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/dphans/DPNotify.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 2C60C1996D007C9FD8D3D8C844008BFFB5028D28 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 2C60C1996D007C9FD8D3D8C844008BFFB5028D28 36 | IDESourceControlWCCName 37 | DPNotify 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /DemoDPNotify.xcodeproj/project.xcworkspace/xcuserdata/baophan.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dphans/DPNotify/56dc9661ec89dbb85f89ff4543b12ce712ff6c1d/DemoDPNotify.xcodeproj/project.xcworkspace/xcuserdata/baophan.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /DemoDPNotify.xcodeproj/xcuserdata/baophan.xcuserdatad/xcschemes/DemoDPNotify.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /DemoDPNotify.xcodeproj/xcuserdata/baophan.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DemoDPNotify.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 8D746C661B3D0F3800372FA0 16 | 17 | primary 18 | 19 | 20 | 8D746C7B1B3D0F3900372FA0 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /DemoDPNotify/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // DemoDPNotify 4 | // 5 | // Created by @baophan94 on 6/26/15. 6 | // Copyright (c) 2015 @baophan94. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /DemoDPNotify/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /DemoDPNotify/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /DemoDPNotify/DPNotify/DPNotify.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DPNotify.swift 3 | // DemoDPNotify 4 | // 5 | // Created by @baophan94 on 6/26/15. 6 | // Contact: www.dinophan.com - baophan94@icloud.com 7 | // Copyright (c) 2015 @baophan94. All rights reserved. 8 | // 9 | // A guide to the main features is available at: 10 | // www.dinophan.com 11 | // 12 | 13 | import UIKit 14 | 15 | /************* USAGE ****************** 16 | 17 | * Show notify: 18 | 19 | showNotifyInView(inView: UIView, title: String, dismissOnTap: Bool) {} 20 | showNotifyInView(inView: UIView, title: String, dismissOnTap: Bool, notifyType: DPNotifyType) {} 21 | showNotifyInView(inView: UIView, title: String, dismissOnTap: Bool, notifyType: DPNotifyType, delay: NSTimeInterval) {} 22 | showNotifyInView(inView: UIView, title: String, dismissOnTap: Bool, notifyType: DPNotifyType, delay: NSTimeInterval, completionHandler: () -> Void) {} 23 | 24 | 25 | * Dismiss notify: 26 | 27 | dismissNotify() {} 28 | dismissNotify(completion: () -> Void) {} 29 | 30 | ***************************************/ 31 | 32 | enum DPNotifyType { 33 | case DEFAULT 34 | case DANGER 35 | case WARNING 36 | case SUCCESS 37 | case DISABLED 38 | } 39 | 40 | class DPNotify: NSObject { 41 | 42 | static let sharedNotify = DPNotify() 43 | 44 | var bannerBackgroundColor: UIColor! = UIColor(white: 0.2, alpha: 0.7) 45 | var bannerForegroundColor: UIColor! = UIColor.whiteColor() 46 | var tapToDismiss: Bool! = true 47 | var delayTimer: NSTimeInterval! = 1.0 48 | var bannerType: DPNotifyType! = .DEFAULT 49 | var notifyTitle: String! = "" 50 | var notifyTitleFont: UIFont! = UIFont.systemFontOfSize(17.0) 51 | private var bannerView: UIView! 52 | private var tapGesture: UITapGestureRecognizer? 53 | 54 | 55 | func showNotifyInView(inView: UIView, title: String, dismissOnTap: Bool) { 56 | 57 | if self.bannerView != nil { 58 | if self.tapGesture != nil { 59 | self.bannerView.removeGestureRecognizer(self.tapGesture!) 60 | self.tapGesture = nil 61 | } 62 | self.bannerView.removeFromSuperview() 63 | self.bannerView = nil 64 | } 65 | 66 | self.notifyTitle = title 67 | self.tapToDismiss = dismissOnTap 68 | 69 | let containerFrame: CGRect = inView.frame 70 | self.bannerView = UIView() 71 | self.bannerView.backgroundColor = self.bannerBackgroundColor 72 | 73 | var calculationView: UITextView = UITextView() 74 | calculationView.attributedText = NSAttributedString(string: self.notifyTitle, attributes: 75 | [ 76 | NSFontAttributeName: notifyTitleFont 77 | ]) 78 | let size: CGSize = calculationView.sizeThatFits( 79 | CGSizeMake(containerFrame.width - 16, CGFloat(FLT_MAX))) 80 | var titleView = UITextView( 81 | frame: CGRectMake(8, 0, containerFrame.width - 16, size.height)) 82 | titleView = applyTextViewStyle(titleView) 83 | self.bannerView.addSubview(titleView) 84 | self.bannerView.alpha = 0 85 | self.bannerView.frame = CGRectMake(0, -titleView.frame.size.height, containerFrame.width, titleView.frame.size.height) 86 | inView.addSubview(self.bannerView) 87 | 88 | addTapToDismissGesture() 89 | 90 | UIView.animateWithDuration(0.2, animations: { () -> Void in 91 | self.bannerView.alpha = 1 92 | titleView.alpha = 1 93 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height + 5) 94 | }) { (Bool) -> Void in 95 | if self.bannerView != nil { 96 | UIView.animateWithDuration(0.2, animations: { () -> Void in 97 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height) 98 | }, completion: { (Bool) -> Void in 99 | 100 | }) 101 | } 102 | } 103 | } 104 | 105 | func showNotifyInView(inView: UIView, title: String, dismissOnTap: Bool, notifyType: DPNotifyType) { 106 | 107 | if self.bannerView != nil { 108 | if self.tapGesture != nil { 109 | self.bannerView.removeGestureRecognizer(self.tapGesture!) 110 | self.tapGesture = nil 111 | } 112 | self.bannerView.removeFromSuperview() 113 | self.bannerView = nil 114 | } 115 | 116 | switch notifyType { 117 | case DPNotifyType.DEFAULT: self.applyDefaultType() 118 | case DPNotifyType.DANGER: self.applyDangerType() 119 | case DPNotifyType.DISABLED: self.applyDisabledType() 120 | case DPNotifyType.SUCCESS: self.applySuccessType() 121 | case DPNotifyType.WARNING: self.applyWarningType() 122 | default: self.applyDefaultType() 123 | } 124 | 125 | self.notifyTitle = title 126 | self.tapToDismiss = dismissOnTap 127 | 128 | let containerFrame: CGRect = inView.frame 129 | self.bannerView = UIView() 130 | self.bannerView.backgroundColor = self.bannerBackgroundColor 131 | 132 | var calculationView: UITextView = UITextView() 133 | calculationView.attributedText = NSAttributedString(string: self.notifyTitle, attributes: 134 | [ 135 | NSFontAttributeName: notifyTitleFont 136 | ]) 137 | let size: CGSize = calculationView.sizeThatFits( 138 | CGSizeMake(containerFrame.width - 16, CGFloat(FLT_MAX))) 139 | var titleView = UITextView( 140 | frame: CGRectMake(8, 0, containerFrame.width - 16, size.height)) 141 | titleView = applyTextViewStyle(titleView) 142 | self.bannerView.addSubview(titleView) 143 | self.bannerView.alpha = 0 144 | self.bannerView.frame = CGRectMake(0, -titleView.frame.size.height, containerFrame.width, titleView.frame.size.height) 145 | inView.addSubview(self.bannerView) 146 | 147 | if dismissOnTap == true { 148 | addTapToDismissGesture() 149 | } 150 | 151 | UIView.animateWithDuration(0.2, animations: { () -> Void in 152 | self.bannerView.alpha = 1 153 | titleView.alpha = 1 154 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height + 5) 155 | }) { (Bool) -> Void in 156 | if self.bannerView != nil { 157 | UIView.animateWithDuration(0.2, animations: { () -> Void in 158 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height) 159 | }) 160 | } 161 | } 162 | } 163 | 164 | func showNotifyInView(inView: UIView, title: String, dismissOnTap: Bool, notifyType: DPNotifyType, delay: NSTimeInterval) { 165 | 166 | if self.bannerView != nil { 167 | if self.tapGesture != nil { 168 | self.bannerView.removeGestureRecognizer(self.tapGesture!) 169 | self.tapGesture = nil 170 | } 171 | self.bannerView.removeFromSuperview() 172 | self.bannerView = nil 173 | } 174 | 175 | switch notifyType { 176 | case DPNotifyType.DEFAULT: self.applyDefaultType() 177 | case DPNotifyType.DANGER: self.applyDangerType() 178 | case DPNotifyType.DISABLED: self.applyDisabledType() 179 | case DPNotifyType.SUCCESS: self.applySuccessType() 180 | case DPNotifyType.WARNING: self.applyWarningType() 181 | default: self.applyDefaultType() 182 | } 183 | 184 | self.delayTimer = delay 185 | 186 | self.notifyTitle = title 187 | self.tapToDismiss = dismissOnTap 188 | 189 | let containerFrame: CGRect = inView.frame 190 | self.bannerView = UIView() 191 | self.bannerView.backgroundColor = self.bannerBackgroundColor 192 | 193 | var calculationView: UITextView = UITextView() 194 | calculationView.attributedText = NSAttributedString(string: self.notifyTitle, attributes: 195 | [ 196 | NSFontAttributeName: notifyTitleFont 197 | ]) 198 | let size: CGSize = calculationView.sizeThatFits( 199 | CGSizeMake(containerFrame.width - 16, CGFloat(FLT_MAX))) 200 | var titleView = UITextView( 201 | frame: CGRectMake(8, 0, containerFrame.width - 16, size.height)) 202 | titleView = applyTextViewStyle(titleView) 203 | self.bannerView.addSubview(titleView) 204 | self.bannerView.alpha = 0 205 | self.bannerView.frame = CGRectMake(0, -titleView.frame.size.height, containerFrame.width, titleView.frame.size.height) 206 | inView.addSubview(self.bannerView) 207 | 208 | if dismissOnTap == true { 209 | addTapToDismissGesture() 210 | } 211 | 212 | UIView.animateWithDuration(0.2, animations: { () -> Void in 213 | self.bannerView.alpha = 1 214 | titleView.alpha = 1 215 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height + 5) 216 | }) { (Bool) -> Void in 217 | if self.bannerView != nil { 218 | UIView.animateWithDuration(0.2, animations: { () -> Void in 219 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height) 220 | }, completion: { (Bool) -> Void in 221 | if self.delayTimer > 0 { 222 | UIView.animateWithDuration(self.delayTimer, animations: { () -> Void in 223 | if self.bannerView != nil { 224 | self.bannerView.alpha = 0.8 225 | } 226 | }, completion: { (cpl) -> Void in 227 | if cpl == true { 228 | self.dismissNotify() 229 | } 230 | }) 231 | } 232 | }) 233 | } 234 | } 235 | } 236 | 237 | func showNotifyInView( 238 | inView: UIView, 239 | title: String, 240 | dismissOnTap: Bool, 241 | notifyType: DPNotifyType, 242 | delay: NSTimeInterval, 243 | completionHandler: () -> Void) { 244 | 245 | if self.bannerView != nil { 246 | if self.tapGesture != nil { 247 | self.bannerView.removeGestureRecognizer(self.tapGesture!) 248 | self.tapGesture = nil 249 | } 250 | self.bannerView.removeFromSuperview() 251 | self.bannerView = nil 252 | } 253 | 254 | switch notifyType { 255 | case DPNotifyType.DEFAULT: self.applyDefaultType() 256 | case DPNotifyType.DANGER: self.applyDangerType() 257 | case DPNotifyType.DISABLED: self.applyDisabledType() 258 | case DPNotifyType.SUCCESS: self.applySuccessType() 259 | case DPNotifyType.WARNING: self.applyWarningType() 260 | default: self.applyDefaultType() 261 | } 262 | 263 | self.delayTimer = delay 264 | 265 | self.notifyTitle = title 266 | self.tapToDismiss = dismissOnTap 267 | 268 | let containerFrame: CGRect = inView.frame 269 | self.bannerView = UIView() 270 | self.bannerView.backgroundColor = self.bannerBackgroundColor 271 | 272 | var calculationView: UITextView = UITextView() 273 | calculationView.attributedText = NSAttributedString(string: self.notifyTitle, attributes: 274 | [ 275 | NSFontAttributeName: notifyTitleFont 276 | ]) 277 | let size: CGSize = calculationView.sizeThatFits( 278 | CGSizeMake(containerFrame.width - 16, CGFloat(FLT_MAX))) 279 | var titleView = UITextView( 280 | frame: CGRectMake(8, 0, containerFrame.width - 16, size.height)) 281 | titleView = applyTextViewStyle(titleView) 282 | self.bannerView.addSubview(titleView) 283 | self.bannerView.alpha = 0 284 | self.bannerView.frame = CGRectMake(0, -titleView.frame.size.height, containerFrame.width, titleView.frame.size.height) 285 | inView.addSubview(self.bannerView) 286 | 287 | if dismissOnTap == true { 288 | addTapToDismissGesture() 289 | } 290 | 291 | UIView.animateWithDuration(0.2, animations: { () -> Void in 292 | self.bannerView.alpha = 1 293 | titleView.alpha = 1 294 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height + 5) 295 | }) { (Bool) -> Void in 296 | if self.bannerView != nil { 297 | UIView.animateWithDuration(0.2, animations: { () -> Void in 298 | self.bannerView.frame = CGRectMake(0, 0, containerFrame.width, titleView.frame.size.height) 299 | }, completion: { (Bool) -> Void in 300 | completionHandler() 301 | if self.delayTimer > 0 { 302 | UIView.animateWithDuration(self.delayTimer, animations: { () -> Void in 303 | if self.bannerView != nil { 304 | self.bannerView.alpha = 0.8 305 | } 306 | }, completion: { (cpl) -> Void in 307 | if cpl == true { 308 | self.dismissNotify() 309 | } 310 | }) 311 | } 312 | }) 313 | } 314 | } 315 | } 316 | 317 | func dismissNotify() { 318 | if self.bannerView != nil { 319 | let curFrame = self.bannerView.frame 320 | UIView.animateWithDuration(0.2, animations: { () -> Void in 321 | self.bannerView.alpha = 0 322 | self.bannerView.frame = CGRectMake(0, -curFrame.height, curFrame.width, curFrame.height) 323 | }, completion: { (cpl) -> Void in 324 | if (cpl == true) { 325 | if self.bannerView != nil { 326 | self.bannerView = nil 327 | } 328 | } 329 | }) 330 | } 331 | } 332 | 333 | func dismissNotify(completion: () -> Void) { 334 | if self.bannerView != nil { 335 | let curFrame = self.bannerView.frame 336 | UIView.animateWithDuration(0.2, animations: { () -> Void in 337 | self.bannerView.alpha = 0 338 | self.bannerView.frame = CGRectMake(0, -curFrame.height, curFrame.width, curFrame.height) 339 | }, completion: { (cpl) -> Void in 340 | if cpl == true { 341 | if self.bannerView != nil { 342 | self.bannerView = nil 343 | } 344 | } 345 | completion() 346 | }) 347 | } 348 | } 349 | 350 | func showCompletionHandler(completion: (Bool) -> Void) { 351 | 352 | } 353 | 354 | func addTapToDismissGesture() { 355 | if self.tapGesture != nil { 356 | self.tapGesture = nil 357 | } 358 | if tapToDismiss == true { 359 | self.tapGesture = UITapGestureRecognizer(target: self, action: "dismissNotify") 360 | self.bannerView.addGestureRecognizer(tapGesture!) 361 | } 362 | } 363 | 364 | // MARK: Banner Type 365 | func applyDefaultType() { 366 | notifyTitle = "" 367 | notifyTitleFont = UIFont.systemFontOfSize(17) 368 | bannerBackgroundColor = color(0x9E9E9E, alpha: 1.0) 369 | bannerForegroundColor = UIColor.whiteColor() 370 | delayTimer = 0 371 | } 372 | 373 | func applyDangerType() { 374 | notifyTitle = "" 375 | notifyTitleFont = UIFont.systemFontOfSize(17) 376 | bannerBackgroundColor = color(0xE53935, alpha: 1.0) 377 | bannerForegroundColor = UIColor.whiteColor() 378 | delayTimer = 0 379 | } 380 | 381 | func applyWarningType() { 382 | notifyTitle = "" 383 | notifyTitleFont = UIFont.systemFontOfSize(17) 384 | bannerBackgroundColor = color(0xFF8F00, alpha: 1.0) 385 | bannerForegroundColor = UIColor.whiteColor() 386 | delayTimer = 0 387 | } 388 | 389 | func applySuccessType() { 390 | notifyTitle = "" 391 | notifyTitleFont = UIFont.systemFontOfSize(17) 392 | bannerBackgroundColor = color(0x03A9F4, alpha: 1.0) 393 | bannerForegroundColor = UIColor.whiteColor() 394 | delayTimer = 0 395 | } 396 | 397 | func applyDisabledType() { 398 | notifyTitle = "" 399 | notifyTitleFont = UIFont.systemFontOfSize(17) 400 | bannerBackgroundColor = color(0x000000, alpha: 1.0) 401 | bannerForegroundColor = UIColor.whiteColor() 402 | delayTimer = 0 403 | } 404 | 405 | func color(hex: Int, alpha: CGFloat = 1.0) -> UIColor { 406 | let red = CGFloat((hex & 0xFF0000) >> 16) / 255.0 407 | let green = CGFloat((hex & 0xFF00) >> 8) / 255.0 408 | let blue = CGFloat((hex & 0xFF)) / 255.0 409 | return UIColor(red: red, green: green, blue: blue, alpha: alpha) 410 | } 411 | 412 | func applyTextViewStyle(textView: UITextView) -> UITextView { 413 | textView.text = self.notifyTitle 414 | textView.font = self.notifyTitleFont 415 | textView.alpha = 0 416 | textView.textColor = self.bannerForegroundColor 417 | textView.backgroundColor = UIColor.clearColor() 418 | textView.editable = false 419 | textView.selectable = false 420 | textView.scrollEnabled = false 421 | return textView 422 | } 423 | 424 | } 425 | -------------------------------------------------------------------------------- /DemoDPNotify/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /DemoDPNotify/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.dinophan.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /DemoDPNotify/TableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewController.swift 3 | // DemoDPNotify 4 | // 5 | // Created by @baophan94 on 6/26/15. 6 | // Copyright (c) 2015 @baophan94. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class TableViewController: UITableViewController { 12 | 13 | var items: Array = [ 14 | "Normal", 15 | "Danger", 16 | "Warning", 17 | "Success", 18 | "No connection, please check network connection and try again again again. bla bla ;-)", 19 | "Show with completion handler", 20 | "Dismiss", 21 | "Dismiss with completion handler", 22 | "Show success delay: 1 second", 23 | "Custom banner" 24 | ] 25 | 26 | override func viewDidLoad() { 27 | super.viewDidLoad() 28 | 29 | 30 | } 31 | 32 | // MARK: - Table view data source 33 | 34 | override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 35 | return 1 36 | } 37 | 38 | override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 39 | return items.count 40 | } 41 | 42 | override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 43 | let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell 44 | let bgStdView = UIView() 45 | bgStdView.backgroundColor = UIColor(white: 0.8, alpha: 0.2) 46 | cell.selectedBackgroundView = bgStdView 47 | cell.textLabel?.text = items[indexPath.row] 48 | return cell 49 | } 50 | 51 | override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 52 | tableView.deselectRowAtIndexPath(indexPath, animated: true) 53 | switch indexPath.row { 54 | case 0: DPNotify.sharedNotify.showNotifyInView(view, title: items[indexPath.row], dismissOnTap: true, notifyType: .DEFAULT) 55 | case 1: DPNotify.sharedNotify.showNotifyInView(view, title: items[indexPath.row], dismissOnTap: true, notifyType: .DANGER) 56 | case 2: DPNotify.sharedNotify.showNotifyInView(view, title: items[indexPath.row], dismissOnTap: true, notifyType: .WARNING) 57 | case 3: DPNotify.sharedNotify.showNotifyInView(view, title: items[indexPath.row], dismissOnTap: true, notifyType: .SUCCESS) 58 | case 4: DPNotify.sharedNotify.showNotifyInView(view, title: items[indexPath.row], dismissOnTap: true, notifyType: .DISABLED) 59 | case 5: DPNotify.sharedNotify.showNotifyInView(view, title: items[indexPath.row], dismissOnTap: true, notifyType: .DANGER, delay: 0, completionHandler: { () -> Void in 60 | var alert = UIAlertView(title: "Completed!", message: "Notify showed!", delegate: nil, cancelButtonTitle: "はい!") 61 | alert.show() 62 | }) 63 | case 6: DPNotify.sharedNotify.dismissNotify() 64 | case 7: DPNotify.sharedNotify.dismissNotify({ () -> Void in 65 | var alert = UIAlertView(title: "Completed!", message: "Notify dismissed!", delegate: nil, cancelButtonTitle: "はい!") 66 | alert.show() 67 | }) 68 | case 8: DPNotify.sharedNotify.showNotifyInView(view, title: items[indexPath.row], dismissOnTap: false, notifyType: .SUCCESS, delay: 1.0) 69 | case 9: 70 | DPNotify.sharedNotify.bannerForegroundColor = DPNotify.sharedNotify.color(0x607D8B, alpha: 1) 71 | DPNotify.sharedNotify.bannerBackgroundColor = UIColor(white: 0.8, alpha: 0.8) 72 | DPNotify.sharedNotify.notifyTitleFont = UIFont(name: "Avenir", size: 17.0) 73 | DPNotify.sharedNotify.showNotifyInView(view, title: items[indexPath.row], dismissOnTap: true) 74 | default: break 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /DemoDPNotifyTests/DemoDPNotifyTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DemoDPNotifyTests.swift 3 | // DemoDPNotifyTests 4 | // 5 | // Created by @baophan94 on 6/26/15. 6 | // Copyright (c) 2015 @baophan94. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class DemoDPNotifyTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /DemoDPNotifyTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.dinophan.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DPNotify 2 | DPNotify used to send short notifications on screen simple & quickly for iOS developing using Swift. 3 | 4 | # Preview 5 | ![alt tag](https://github.com/dphans/DPNotify/blob/master/demo.gif) 6 | 7 | # Features 8 | - block syntax. 9 | - delay timer. 10 | - 5 notify styles available (Default, Danger, Warning, Success, Disabled). 11 | - customize font & color. 12 | - tap to dismiss message. 13 | - request more? please contact me (my email below) 14 | 15 | # Installation 16 | Just add file named DPNotify.swift to your project. 17 | 18 | # Examples 19 | 20 | - Show notify in self.view: 21 | ``` swift 22 | DPNotify.sharedNotify.showNotifyInView(view, title: "Awesome :P", dismissOnTap: true, notifyType: .DEFAULT) 23 | ``` 24 | 25 | - Completion handler: 26 | ``` swift 27 | DPNotify.sharedNotify.showNotifyInView(view, 28 | title: items[indexPath.row], 29 | dismissOnTap: true, 30 | notifyType: .DANGER, 31 | delay: 0, 32 | completionHandler: { () -> Void in 33 | var alert = UIAlertView( 34 | title: "Completed!", 35 | message: "Notify showed!", 36 | delegate: nil, 37 | cancelButtonTitle: "Hit ;-)") 38 | alert.show() 39 | }) 40 | ``` 41 | 42 | - Dismiss message: 43 | ``` swift 44 | DPNotify.sharedNotify.dismissNotify() 45 | ``` 46 | ``` swift 47 | DPNotify.sharedNotify.dismissNotify({ () -> Void in 48 | var alert = UIAlertView(title: "Completed!", message: "Notify dismissed!", delegate: nil, cancelButtonTitle: "はい!") 49 | alert.show() 50 | ``` 51 | 52 | - Custom style: 53 | ``` swfit 54 | DPNotify.sharedNotify.bannerForegroundColor = DPNotify.sharedNotify.color(0x607D8B, alpha: 1) 55 | DPNotify.sharedNotify.bannerBackgroundColor = UIColor(white: 0.8, alpha: 0.8) 56 | DPNotify.sharedNotify.notifyTitleFont = UIFont(name: "Avenir", size: 17.0) 57 | DPNotify.sharedNotify.showNotifyInView(view, title: "Hello, Dino Phan :D", dismissOnTap: true) 58 | ``` 59 | 60 | # Contact: 61 | Homepage: https://www.dphans.me - Email: baophan94@icloud.com. 62 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dphans/DPNotify/56dc9661ec89dbb85f89ff4543b12ce712ff6c1d/demo.gif --------------------------------------------------------------------------------