Skip to content

Commit 3eff4e2

Browse files
committed
[master] - Release 2.5.0
1 parent 07c1c00 commit 3eff4e2

9 files changed

+70
-14
lines changed

Example/NotificationBanner/CustomBannerColors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CustomBannerColors: BannerColors {
1717
switch style {
1818
case .danger: return super.color(for: style)
1919
case .info: return super.color(for: style)
20-
case .none: return super.color(for: style)
20+
case .customView: return super.color(for: style)
2121
case .success: return super.color(for: style)
2222
case .warning: return UIColor(red:0.99, green:0.40, blue:0.13, alpha:1.00)
2323
}

Example/NotificationBanner/ExampleViewController.swift

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ extension ExampleViewController: ExampleViewDelegate {
129129
// Basic Warning Notification with Custom Color
130130
let banner = NotificationBanner(title: "Basic Notification",
131131
subtitle: "Must Be Dismissed Manually",
132-
style: .none)
132+
style: .customView)
133133
banner.delegate = self
134134
banner.backgroundColor = blockColor(at: IndexPath(row: 5, section: 0))
135135
banner.autoDismiss = false
@@ -230,19 +230,36 @@ extension ExampleViewController: ExampleViewDelegate {
230230
let banner = FloatingNotificationBanner(title: "Success Notification",
231231
subtitle: "This type of banner floats and has the capability of growing to an infinite amount of lines. This one also has a shadow.",
232232
style: .success)
233+
233234
banner.delegate = self
234235
banner.show(queuePosition: selectedQueuePosition(),
235236
bannerPosition: selectedBannerPosition(),
236237
cornerRadius: 10,
237238
shadowBlurRadius: 15)
238-
default:
239+
case 1:
239240
let banner = FloatingNotificationBanner(title: "Danger Notification",
240241
subtitle: "This type of banner floats and has the capability of growing to an infinite amount of lines.",
241242
style: .danger)
242243
banner.delegate = self
243244
banner.show(queuePosition: selectedQueuePosition(),
244245
bannerPosition: selectedBannerPosition(),
245246
cornerRadius: 10)
247+
case 2:
248+
let banner = FloatingNotificationBanner(title: "Info Notification",
249+
subtitle: "With adjusted transparency!",
250+
style: .info)
251+
banner.delegate = self
252+
banner.transparency = 0.75
253+
banner.show(queuePosition: selectedQueuePosition(),
254+
bannerPosition: selectedBannerPosition(),
255+
cornerRadius: 10)
256+
default:
257+
let banner = FloatingNotificationBanner(customView: NorthCarolinaBannerView())
258+
banner.delegate = self
259+
banner.show(queuePosition: selectedQueuePosition(),
260+
bannerPosition: selectedBannerPosition(),
261+
cornerRadius: 10,
262+
shadowBlurRadius: 15)
246263
}
247264
}
248265

@@ -314,7 +331,7 @@ extension ExampleViewController: ExampleViewDelegate {
314331
case 3:
315332
return 2
316333
case 4:
317-
return 2
334+
return 4
318335
case 5:
319336
return 6
320337
default:
@@ -420,6 +437,10 @@ extension ExampleViewController: ExampleViewDelegate {
420437
return ("Success Notification", "This type of banner can float and can have its cornerRadius property adjusted")
421438
case 1:
422439
return ("Danger Notification", "This type of banner can float and can have its cornerRadius property adjusted")
440+
case 2:
441+
return ("Info Notification", "With adjusted transparency!")
442+
case 3:
443+
return ("Tarheels Notification", "This type of banner can float and can have its cornerRadius property adjusted")
423444
default:
424445
return ("", nil)
425446
}
@@ -453,6 +474,13 @@ extension ExampleViewController: ExampleViewDelegate {
453474
default:
454475
return nil
455476
}
477+
} else if indexPath.section == 4 {
478+
switch indexPath.row {
479+
case 3:
480+
return #imageLiteral(resourceName: "unc_logo")
481+
default:
482+
return nil
483+
}
456484
}
457485

458486
return nil

NotificationBanner/Classes/BannerColors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class BannerColors: BannerColorsProtocol {
2929
switch style {
3030
case .danger: return UIColor(red:0.90, green:0.31, blue:0.26, alpha:1.00)
3131
case .info: return UIColor(red:0.23, green:0.60, blue:0.85, alpha:1.00)
32-
case .none: return UIColor.clear
32+
case .customView: return UIColor.clear
3333
case .success: return UIColor(red:0.22, green:0.80, blue:0.46, alpha:1.00)
3434
case .warning: return UIColor(red:1.00, green:0.66, blue:0.16, alpha:1.00)
3535
}

NotificationBanner/Classes/BannerStyle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Foundation
2222
public enum BannerStyle: Int {
2323
case danger
2424
case info
25-
case none
25+
case customView
2626
case success
2727
case warning
2828
}

NotificationBanner/Classes/BaseNotificationBanner.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class BaseNotificationBanner: UIView {
4848

4949
/// The delegate of the notification banner
5050
public weak var delegate: NotificationBannerDelegate?
51+
52+
/// The style of the notification banner
53+
public let style: BannerStyle
5154

5255
/// The height of the banner when it is presented
5356
public var bannerHeight: CGFloat {
@@ -82,6 +85,14 @@ public class BaseNotificationBanner: UIView {
8285
}
8386
}
8487

88+
/// The transparency of the background of the notification banner
89+
public var transparency: CGFloat = 1.0 {
90+
didSet {
91+
let color = backgroundColor
92+
self.backgroundColor = color
93+
}
94+
}
95+
8596
/// The type of haptic to generate when a banner is displayed
8697
public var haptic: BannerHaptic = .heavy
8798

@@ -154,12 +165,14 @@ public class BaseNotificationBanner: UIView {
154165
get {
155166
return contentView.backgroundColor
156167
} set {
157-
contentView.backgroundColor = newValue
158-
spacerView.backgroundColor = newValue
168+
let color = newValue?.withAlphaComponent(transparency)
169+
contentView.backgroundColor = color
170+
spacerView.backgroundColor = color
159171
}
160172
}
161173

162174
init(style: BannerStyle, colors: BannerColorsProtocol? = nil) {
175+
self.style = style
163176
super.init(frame: .zero)
164177

165178
spacerView = UIView()
@@ -179,8 +192,8 @@ public class BaseNotificationBanner: UIView {
179192
addGestureRecognizer(swipeUpGesture)
180193
}
181194

182-
required public init?(coder aDecoder: NSCoder) {
183-
super.init(coder: aDecoder)
195+
required init?(coder aDecoder: NSCoder) {
196+
fatalError("init(coder:) has not been implemented")
184197
}
185198

186199
deinit {

NotificationBanner/Classes/FloatingNotificationBanner.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ public class FloatingNotificationBanner: GrowingNotificationBanner {
6464
}
6565
}
6666

67+
public init(customView: UIView) {
68+
super.init(style: .customView)
69+
contentView.addSubview(customView)
70+
customView.snp.makeConstraints { (make) in
71+
make.edges.equalTo(contentView)
72+
}
73+
74+
spacerView.backgroundColor = customView.backgroundColor
75+
}
76+
6777
/**
6878
Convenience function to display banner with non .zero default edge insets
6979
*/
@@ -84,6 +94,11 @@ public class FloatingNotificationBanner: GrowingNotificationBanner {
8494

8595
if let cornerRadius = cornerRadius {
8696
contentView.layer.cornerRadius = cornerRadius
97+
contentView.subviews.last?.layer.cornerRadius = cornerRadius
98+
}
99+
100+
if style == .customView, let customView = contentView.subviews.last {
101+
customView.backgroundColor = customView.backgroundColor?.withAlphaComponent(transparency)
87102
}
88103

89104
show(queuePosition: queuePosition,
@@ -116,7 +131,7 @@ private extension FloatingNotificationBanner {
116131
cornerRadius: CGFloat = 0,
117132
offset: UIOffset = .zero,
118133
edgeInsets: UIEdgeInsets? = nil) {
119-
134+
guard blurRadius > 0 else { return }
120135
contentView.layer.shadowColor = color.cgColor
121136
contentView.layer.shadowOpacity = Float(opacity)
122137
contentView.layer.shadowRadius = blurRadius

NotificationBanner/Classes/NotificationBanner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public class NotificationBanner: BaseNotificationBanner {
156156
}
157157

158158
public init(customView: UIView) {
159-
super.init(style: .none)
159+
super.init(style: .customView)
160160
contentView.addSubview(customView)
161161
customView.snp.makeConstraints { (make) in
162162
make.edges.equalTo(contentView)

NotificationBanner/Classes/StatusBarNotificationBanner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class StatusBarNotificationBanner: BaseNotificationBanner {
7373
}
7474

7575
public init(customView: UIView) {
76-
super.init(style: .none)
76+
super.init(style: .customView)
7777
contentView.addSubview(customView)
7878
customView.snp.makeConstraints { make in
7979
make.edges.equalTo(contentView)

NotificationBannerSwift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Pod::Spec.new do |s|
33
s.name = 'NotificationBannerSwift'
4-
s.version = '2.4.1'
4+
s.version = '2.5.0'
55
s.summary = 'The easiest way to display in app notification banners in iOS.'
66

77
s.description = <<-DESC

0 commit comments

Comments
 (0)