1111
1212#import " CSLayerStealingBlurView.h"
1313#import " CSNativeBlurView.h"
14+ #import " CSColorView.h"
1415
1516@implementation CSNotificationView
1617
@@ -100,46 +101,38 @@ + (CSNotificationView*)notificationViewWithParentViewController:(UIViewControlle
100101
101102#pragma mark - lifecycle
102103
103- - (instancetype )initWithParentViewController : (UIViewController*)viewController
104+ - (instancetype )initWithParentViewController : (UIViewController *)viewController blurView : (UIView<CSNotificationViewBlurViewProtocol> *) blurView
104105{
105106 self = [super initWithFrame: CGRectZero];
106107 if (self) {
107-
108+
108109 self.backgroundColor = [UIColor clearColor ];
109-
110+
110111 // Blur view
111112 {
112-
113- if (floor (NSFoundationVersionNumber ) > NSFoundationVersionNumber_iOS_7_1) {
114- // Use native effects
115- self.blurView = [[CSNativeBlurView alloc ] initWithFrame: CGRectZero];
116- } else {
117- // Use layer stealing
118- self.blurView = [[CSLayerStealingBlurView alloc ] initWithFrame: CGRectZero];
119- }
120-
113+ self.blurView = blurView;
121114 self.blurView .userInteractionEnabled = NO ;
122115 self.blurView .translatesAutoresizingMaskIntoConstraints = NO ;
123116 self.blurView .clipsToBounds = NO ;
124117 [self insertSubview: self .blurView atIndex: 0 ];
125-
118+
126119 }
127-
120+
128121 // Parent view
129122 {
130123 self.parentViewController = viewController;
131-
124+
132125 NSAssert (!([self .parentViewController isKindOfClass: [UITableViewController class ]] && !self.parentViewController.navigationController), @"Due to a bug in iOS 7.0.1|2|3 UITableViewController, CSNotificationView cannot present in UITableViewController without a parent UINavigationController");
133-
126+
134127 if (self.parentViewController .navigationController ) {
135128 self.parentNavigationController = self.parentViewController .navigationController ;
136129 }
137130 if ([self .parentViewController isKindOfClass: [UINavigationController class ]]) {
138131 self.parentNavigationController = (UINavigationController*)self.parentViewController ;
139132 }
140-
133+
141134 }
142-
135+
143136 // Notifications
144137 {
145138 [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (navigationControllerWillShowViewControllerNotification: ) name: kCSNotificationViewUINavigationControllerWillShowViewControllerNotification object: nil ];
@@ -150,33 +143,33 @@ - (instancetype)initWithParentViewController:(UIViewController*)viewController
150143 {
151144 [self addObserver: self forKeyPath: kCSNavigationBarBoundsKeyPath options: NSKeyValueObservingOptionNew context: kCSNavigationBarObservationContext ];
152145 }
153-
146+
154147 // Content views
155148 {
156149 // textLabel
157150 {
158151 _textLabel = [[UILabel alloc ] init ];
159-
152+
160153 _textLabel.textColor = [UIColor whiteColor ];
161154 _textLabel.backgroundColor = [UIColor clearColor ];
162155 _textLabel.translatesAutoresizingMaskIntoConstraints = NO ;
163-
156+
164157 _textLabel.numberOfLines = 2 ;
165158 _textLabel.minimumScaleFactor = 0.6 ;
166159 _textLabel.lineBreakMode = NSLineBreakByTruncatingTail;
167-
160+
168161 UIFontDescriptor* textLabelFontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle: UIFontTextStyleBody];
169162 _textLabel.font = [UIFont fontWithDescriptor: textLabelFontDescriptor size: 17 .0f ];
170163 _textLabel.adjustsFontSizeToFitWidth = YES ;
171-
164+
172165 [self addSubview: _textLabel];
173166 }
174167 // symbolView
175168 {
176169 [self updateSymbolView ];
177170 }
178171 }
179-
172+
180173 // Interaction
181174 {
182175 // Tap gesture
@@ -185,11 +178,29 @@ - (instancetype)initWithParentViewController:(UIViewController*)viewController
185178 }
186179
187180 self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
188-
181+
189182 }
190183 return self;
191184}
192185
186+ - (instancetype )initWithParentViewControllerWithoutBlur : (UIViewController *)viewController
187+ {
188+ return [self initWithParentViewController: viewController blurView: [[CSColorView alloc ] init ]];
189+ }
190+
191+ - (instancetype )initWithParentViewController : (UIViewController*)viewController
192+ {
193+ UIView<CSNotificationViewBlurViewProtocol> *blurView;
194+ if (floor (NSFoundationVersionNumber ) > NSFoundationVersionNumber_iOS_7_1) {
195+ // Use native effects
196+ blurView = [[CSNativeBlurView alloc ] initWithFrame: CGRectZero];
197+ } else {
198+ // Use layer stealing
199+ blurView = [[CSLayerStealingBlurView alloc ] initWithFrame: CGRectZero];
200+ }
201+ return [self initWithParentViewController: viewController blurView: blurView];
202+ }
203+
193204- (void )dealloc
194205{
195206 [[NSNotificationCenter defaultCenter ] removeObserver: self ];
0 commit comments