From 7881704e644e594c9517003103cda447d1e88303 Mon Sep 17 00:00:00 2001 From: Sarah Lensing Date: Mon, 21 Nov 2011 18:02:35 -0500 Subject: [PATCH 1/3] MTUIStatusBarStyleCustom --- MTStatusBarOverlay.h | 32 +++++++++++++++-- MTStatusBarOverlay.m | 81 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 104 insertions(+), 9 deletions(-) diff --git a/MTStatusBarOverlay.h b/MTStatusBarOverlay.h index c864d37..a31ef1d 100755 --- a/MTStatusBarOverlay.h +++ b/MTStatusBarOverlay.h @@ -27,6 +27,13 @@ #pragma mark Definitions and Types //=========================================================== +typedef enum MTUIStatusBarStyle { + MTUIStatusBarStyleDefault, + MTUIStatusBarStyleBlackTranslucent, + MTUIStatusBarStyleBlackOpaque, + MTUIStatusBarStyleCustom +} MTUIStatusBarStyle; + // Animation that happens, when the user touches the status bar overlay typedef enum MTStatusBarOverlayAnimation { MTStatusBarOverlayAnimationNone, // nothing happens @@ -78,8 +85,29 @@ typedef enum MTMessageType { a detail-view that shows additional information. You can show a history of all the previous messages for free by setting historyEnabled to YES */ -@interface MTStatusBarOverlay : UIWindow - +@interface MTStatusBarOverlay : UIWindow +// only used if MTUIStatusBarStyleCustom:default is kDarkCustomThemeTextColor +@property (nonatomic, assign) UIColor *customThemeTextColor; +// only used if MTUIStatusBarStyleCustom:default is kDarkThemeErrorMessageTextColor +@property (nonatomic, assign) UIColor *customThemeErrorMessageTextColor; +// only used if MTUIStatusBarStyleCustom:default is kDarkThemeFinishedMessageTextColor +@property (nonatomic, assign) UIColor *customThemeFinishedMessageTextColor; +// only used if MTUIStatusBarStyleCustom:default is kDarkThemeActivityIndicatorViewStyle +@property (nonatomic, assign) UIActivityIndicatorViewStyle customThemeActivityIndicatorViewStyle; +// only used if MTUIStatusBarStyleCustom:default is kDarkThemeDetailViewBackgroundColor +@property (nonatomic, assign) UIColor *customThemeDetailViewBackgroundColor; +// only used if MTUIStatusBarStyleCustom:default is kDarkThemeDetailViewBorderColor +@property (nonatomic, assign) UIColor *customThemeDetailViewBorderColor; +// only used if MTUIStatusBarStyleCustom:default is kDarkThemeHistoryTextColor +@property (nonatomic, assign) UIColor *customThemeHistoryTextColor; +// only used if MTUIStatusBarStyleCustom:default is [UIColor blackColor] +@property (nonatomic, assign) UIColor *customFinishBarBackgroundColor; +// only used if MTUIStatusBarStyleCustom:default is [UIColor blackColor] +@property (nonatomic, assign) UIColor *customFailBarBackgroundColor; +// only used if MTUIStatusBarStyleCustom:default is [UIColor blackColor] +@property (nonatomic, assign) UIColor *customActivityBarBackgroundColor; +// the default is set to whatever status bar style your app has +@property (nonatomic, assign) MTUIStatusBarStyle statusBarStyle; // the view that holds all the components of the overlay (except for the detailView) @property (nonatomic, strong) UIView *backgroundView; // the detailView is shown when animation is set to "FallDown" diff --git a/MTStatusBarOverlay.m b/MTStatusBarOverlay.m index 01264b6..e1e7b68 100755 --- a/MTStatusBarOverlay.m +++ b/MTStatusBarOverlay.m @@ -188,6 +188,7 @@ @interface MTStatusBarOverlay () @property (nonatomic, assign) BOOL forcedToHide; @property (nonatomic, strong, readwrite) NSString *lastPostedMessage; +- (void)setupStatusBarStyle; // intern method that posts a new entry to the message-queue - (void)postMessage:(NSString *)message type:(MTMessageType)messageType duration:(NSTimeInterval)duration animated:(BOOL)animated immediate:(BOOL)immediate; // intern method that clears the messageQueue and then posts a new entry to it @@ -241,6 +242,17 @@ - (void)applicationWillResignActive:(NSNotification *)notifaction; @implementation MTStatusBarOverlay +@synthesize customThemeTextColor = customThemeTextColor_; +@synthesize customThemeErrorMessageTextColor = customThemeErrorMessageTextColor_; +@synthesize customThemeFinishedMessageTextColor = customThemeFinishedMessageTextColor_; +@synthesize customThemeActivityIndicatorViewStyle = customThemeActivityIndicatorViewStyle_; +@synthesize customThemeDetailViewBackgroundColor = customThemeDetailViewBackgroundColor_; +@synthesize customThemeDetailViewBorderColor = customThemeDetailViewBorderColor_; +@synthesize customThemeHistoryTextColor = customThemeHistoryTextColor_; +@synthesize customFinishBarBackgroundColor = customFinishBarBackgroundColor_; +@synthesize customFailBarBackgroundColor = customFailBarBackgroundColor_; +@synthesize customActivityBarBackgroundColor = customActivityBarBackgroundColor_; +@synthesize statusBarStyle = statusBarStyle_; @synthesize backgroundView = backgroundView_; @synthesize detailView = detailView_; @synthesize statusBarBackgroundImageView = statusBarBackgroundImageView_; @@ -286,6 +298,9 @@ - (id)initWithFrame:(CGRect)frame { statusBarFrame.size.width = 320.f; } + // setup statusBarStyle + [self setupStatusBarStyle]; + // Place the window on the correct level and position self.windowLevel = UIWindowLevelStatusBar+1.f; self.frame = statusBarFrame; @@ -458,6 +473,22 @@ - (void)dealloc { #pragma mark - #pragma mark Status Bar Appearance //////////////////////////////////////////////////////////////////////// +- (void)setupStatusBarStyle { + UIStatusBarStyle style = [UIApplication sharedApplication].statusBarStyle; + switch (style) { + case UIStatusBarStyleDefault: + statusBarStyle_ = MTUIStatusBarStyleDefault; + break; + case UIStatusBarStyleBlackOpaque: + statusBarStyle_ = MTUIStatusBarStyleBlackOpaque; + break; + case UIStatusBarStyleBlackTranslucent: + statusBarStyle_ = MTUIStatusBarStyleBlackTranslucent; + break; + default: + break; + } +} - (void)addSubviewToBackgroundView:(UIView *)view { view.userInteractionEnabled = NO; @@ -667,9 +698,8 @@ - (void)showNextMessage { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(clearHistory) object:nil]; // update UI depending on current status bar style - UIStatusBarStyle statusBarStyle = [UIApplication sharedApplication].statusBarStyle; - [self setStatusBarBackgroundForStyle:statusBarStyle]; - [self setColorSchemeForStatusBarStyle:statusBarStyle messageType:messageType]; + [self setStatusBarBackgroundForStyle:statusBarStyle_]; + [self setColorSchemeForStatusBarStyle:statusBarStyle_ messageType:messageType]; [self updateUIForMessageType:messageType duration:duration]; // if status bar is currently hidden, show it unless it is forced to hide @@ -1061,10 +1091,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID]; cell.textLabel.font = [UIFont boldSystemFontOfSize:10]; - cell.textLabel.textColor = [UIApplication sharedApplication].statusBarStyle == UIStatusBarStyleDefault ? kLightThemeHistoryTextColor : kDarkThemeHistoryTextColor; + cell.textLabel.textColor = statusBarStyle_ == MTUIStatusBarStyleDefault ? kLightThemeHistoryTextColor : kDarkThemeHistoryTextColor; + cell.textLabel.textColor = statusBarStyle_ == MTUIStatusBarStyleCustom ? customThemeHistoryTextColor_ : cell.textLabel.textColor; cell.detailTextLabel.font = [UIFont boldSystemFontOfSize:12]; cell.detailTextLabel.textColor = [UIApplication sharedApplication].statusBarStyle == UIStatusBarStyleDefault ? kLightThemeHistoryTextColor : kDarkThemeHistoryTextColor; + cell.detailTextLabel.textColor = statusBarStyle_ == MTUIStatusBarStyleCustom ? customThemeHistoryTextColor_ : cell.detailTextLabel.textColor; } // step 3: set up cell value @@ -1155,7 +1187,7 @@ - (void)applicationDidBecomeActive:(NSNotification *)notifaction { - (void)setStatusBarBackgroundForStyle:(UIStatusBarStyle)style { // gray status bar? // on iPad the Default Status Bar Style is black too - if (style == UIStatusBarStyleDefault && !IsIPad && !IsIPhoneEmulationMode) { + if (statusBarStyle_ == MTUIStatusBarStyleDefault && !IsIPad && !IsIPhoneEmulationMode) { // choose image depending on size if (self.shrinked) { self.statusBarBackgroundImageView.image = [self.defaultStatusBarImageShrinked stretchableImageWithLeftCapWidth:2.0f topCapHeight:0.0f]; @@ -1173,7 +1205,7 @@ - (void)setStatusBarBackgroundForStyle:(UIStatusBarStyle)style { - (void)setColorSchemeForStatusBarStyle:(UIStatusBarStyle)style messageType:(MTMessageType)messageType { // gray status bar? // on iPad the Default Status Bar Style is black too - if (style == UIStatusBarStyleDefault && !IsIPad && !IsIPhoneEmulationMode) { + if (statusBarStyle_ == MTUIStatusBarStyleDefault && !IsIPad && !IsIPhoneEmulationMode) { // set color of labels depending on messageType switch(messageType) { case MTMessageTypeFinish: @@ -1210,7 +1242,7 @@ - (void)setColorSchemeForStatusBarStyle:(UIStatusBarStyle)style messageType:(MTM self.progressView.backgroundColor = [UIColor clearColor]; self.progressView.image = [self.defaultStatusBarImageShrinked stretchableImageWithLeftCapWidth:2.0f topCapHeight:0.0f]; - } else { + } else if (statusBarStyle_ == MTUIStatusBarStyleBlackOpaque || statusBarStyle_ == MTUIStatusBarStyleBlackTranslucent) { // set color of labels depending on messageType switch(messageType) { case MTMessageTypeFinish: @@ -1239,6 +1271,41 @@ - (void)setColorSchemeForStatusBarStyle:(UIStatusBarStyle)style messageType:(MTM self.historyTableView.separatorColor = kDarkThemeDetailViewBorderColor; self.detailTextView.textColor = kDarkThemeHistoryTextColor; + self.progressView.backgroundColor = kProgressViewBackgroundColor; + self.progressView.image = nil; + } + else { //(statusBarStyle_ == MTUIStatusBarStyleBlackCustom ) { + // set color of labels depending on messageType + switch(messageType) { + case MTMessageTypeFinish: + self.statusLabel1.textColor = customThemeFinishedMessageTextColor_ ? customThemeFinishedMessageTextColor_:kDarkThemeFinishedMessageTextColor; + self.statusLabel2.textColor = customThemeFinishedMessageTextColor_ ? customThemeFinishedMessageTextColor_:kDarkThemeFinishedMessageTextColor; + self.finishedLabel.textColor = customThemeFinishedMessageTextColor_ ? customThemeFinishedMessageTextColor_:kDarkThemeFinishedMessageTextColor; + statusBarBackgroundImageView_.backgroundColor = customFinishBarBackgroundColor_ ? customFinishBarBackgroundColor_:[UIColor blackColor]; + break; + case MTMessageTypeError: + self.statusLabel1.textColor = customThemeErrorMessageTextColor_ ? customThemeErrorMessageTextColor_:kDarkThemeErrorMessageTextColor; + self.statusLabel2.textColor = customThemeErrorMessageTextColor_ ? customThemeErrorMessageTextColor_:kDarkThemeErrorMessageTextColor; + self.finishedLabel.textColor = customThemeErrorMessageTextColor_ ? customThemeErrorMessageTextColor_: kDarkThemeErrorMessageTextColor; + statusBarBackgroundImageView_.backgroundColor = customFailBarBackgroundColor_ ? customFailBarBackgroundColor_:[UIColor blackColor]; + break; + default: + self.statusLabel1.textColor = customThemeTextColor_ ? customThemeTextColor_:kDarkThemeTextColor; + self.statusLabel2.textColor = customThemeTextColor_ ? customThemeTextColor_:kDarkThemeTextColor; + self.finishedLabel.textColor = customThemeTextColor_ ? customThemeTextColor_:kDarkThemeTextColor; + statusBarBackgroundImageView_.backgroundColor = customActivityBarBackgroundColor_ ? customActivityBarBackgroundColor_:[UIColor blackColor]; + break; + } + self.statusLabel1.shadowColor = nil; + self.statusLabel2.shadowColor = nil; + self.finishedLabel.shadowColor = nil; + + self.activityIndicator.activityIndicatorViewStyle = customThemeActivityIndicatorViewStyle_ ? customThemeActivityIndicatorViewStyle_:kDarkThemeActivityIndicatorViewStyle; + self.detailView.backgroundColor = customThemeDetailViewBackgroundColor_ ? customThemeDetailViewBackgroundColor_:kDarkThemeDetailViewBackgroundColor;; + self.detailView.layer.borderColor = customThemeDetailViewBorderColor_ ? [customThemeDetailViewBorderColor_ CGColor]:[kDarkThemeDetailViewBorderColor CGColor]; + self.historyTableView.separatorColor = customThemeDetailViewBorderColor_?customThemeDetailViewBorderColor_:kDarkThemeDetailViewBorderColor; + self.detailTextView.textColor = customThemeHistoryTextColor_ ? customThemeHistoryTextColor_: kDarkThemeHistoryTextColor; + self.progressView.backgroundColor = kProgressViewBackgroundColor; self.progressView.image = nil; } From 462f4b9b599204f146730d985dd301a27c217959 Mon Sep 17 00:00:00 2001 From: Sarah Lensing Date: Mon, 21 Nov 2011 18:58:44 -0500 Subject: [PATCH 2/3] misc fixups --- MTStatusBarOverlay.h | 18 +++++++++--------- MTStatusBarOverlay.m | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/MTStatusBarOverlay.h b/MTStatusBarOverlay.h index a31ef1d..283fbd6 100755 --- a/MTStatusBarOverlay.h +++ b/MTStatusBarOverlay.h @@ -87,25 +87,25 @@ typedef enum MTMessageType { */ @interface MTStatusBarOverlay : UIWindow // only used if MTUIStatusBarStyleCustom:default is kDarkCustomThemeTextColor -@property (nonatomic, assign) UIColor *customThemeTextColor; +@property (nonatomic, strong) UIColor *customThemeTextColor; // only used if MTUIStatusBarStyleCustom:default is kDarkThemeErrorMessageTextColor -@property (nonatomic, assign) UIColor *customThemeErrorMessageTextColor; +@property (nonatomic, strong) UIColor *customThemeErrorMessageTextColor; // only used if MTUIStatusBarStyleCustom:default is kDarkThemeFinishedMessageTextColor -@property (nonatomic, assign) UIColor *customThemeFinishedMessageTextColor; +@property (nonatomic, strong) UIColor *customThemeFinishedMessageTextColor; // only used if MTUIStatusBarStyleCustom:default is kDarkThemeActivityIndicatorViewStyle @property (nonatomic, assign) UIActivityIndicatorViewStyle customThemeActivityIndicatorViewStyle; // only used if MTUIStatusBarStyleCustom:default is kDarkThemeDetailViewBackgroundColor -@property (nonatomic, assign) UIColor *customThemeDetailViewBackgroundColor; +@property (nonatomic, strong) UIColor *customThemeDetailViewBackgroundColor; // only used if MTUIStatusBarStyleCustom:default is kDarkThemeDetailViewBorderColor -@property (nonatomic, assign) UIColor *customThemeDetailViewBorderColor; +@property (nonatomic, strong) UIColor *customThemeDetailViewBorderColor; // only used if MTUIStatusBarStyleCustom:default is kDarkThemeHistoryTextColor -@property (nonatomic, assign) UIColor *customThemeHistoryTextColor; +@property (nonatomic, strong) UIColor *customThemeHistoryTextColor; // only used if MTUIStatusBarStyleCustom:default is [UIColor blackColor] -@property (nonatomic, assign) UIColor *customFinishBarBackgroundColor; +@property (nonatomic, strong) UIColor *customFinishBarBackgroundColor; // only used if MTUIStatusBarStyleCustom:default is [UIColor blackColor] -@property (nonatomic, assign) UIColor *customFailBarBackgroundColor; +@property (nonatomic, strong) UIColor *customFailBarBackgroundColor; // only used if MTUIStatusBarStyleCustom:default is [UIColor blackColor] -@property (nonatomic, assign) UIColor *customActivityBarBackgroundColor; +@property (nonatomic, strong) UIColor *customActivityBarBackgroundColor; // the default is set to whatever status bar style your app has @property (nonatomic, assign) MTUIStatusBarStyle statusBarStyle; // the view that holds all the components of the overlay (except for the detailView) diff --git a/MTStatusBarOverlay.m b/MTStatusBarOverlay.m index e1e7b68..a8cbcb5 100755 --- a/MTStatusBarOverlay.m +++ b/MTStatusBarOverlay.m @@ -203,9 +203,9 @@ - (void)contentViewSwipedUp:(UIGestureRecognizer *)gestureRecognizer; - (void)contentViewSwipedDown:(UIGestureRecognizer *)gestureRecognizer; // updates the current status bar background image for the given style and current size -- (void)setStatusBarBackgroundForStyle:(UIStatusBarStyle)style; +- (void)setStatusBarBackgroundForStyle:(MTUIStatusBarStyle)style; // updates the text-colors of the labels for the given style and message type -- (void)setColorSchemeForStatusBarStyle:(UIStatusBarStyle)style messageType:(MTMessageType)messageType; +- (void)setColorSchemeForStatusBarStyle:(MTUIStatusBarStyle)style messageType:(MTMessageType)messageType; // updates the visiblity of the activity indicator and finished-label depending on the type - (void)updateUIForMessageType:(MTMessageType)messageType duration:(NSTimeInterval)duration; // updates the size of the progressView to always cover only the displayed text-frame @@ -1010,7 +1010,7 @@ - (void)setShrinked:(BOOL)shrinked animated:(BOOL)animated { } // update status bar background - [self setStatusBarBackgroundForStyle:[UIApplication sharedApplication].statusBarStyle]; + [self setStatusBarBackgroundForStyle:statusBarStyle_]; }]; } @@ -1184,7 +1184,7 @@ - (void)applicationDidBecomeActive:(NSNotification *)notifaction { #pragma mark Private Methods //////////////////////////////////////////////////////////////////////// -- (void)setStatusBarBackgroundForStyle:(UIStatusBarStyle)style { +- (void)setStatusBarBackgroundForStyle:(MTUIStatusBarStyle)style { // gray status bar? // on iPad the Default Status Bar Style is black too if (statusBarStyle_ == MTUIStatusBarStyleDefault && !IsIPad && !IsIPhoneEmulationMode) { @@ -1202,7 +1202,7 @@ - (void)setStatusBarBackgroundForStyle:(UIStatusBarStyle)style { } } -- (void)setColorSchemeForStatusBarStyle:(UIStatusBarStyle)style messageType:(MTMessageType)messageType { +- (void)setColorSchemeForStatusBarStyle:(MTUIStatusBarStyle)style messageType:(MTMessageType)messageType { // gray status bar? // on iPad the Default Status Bar Style is black too if (statusBarStyle_ == MTUIStatusBarStyleDefault && !IsIPad && !IsIPhoneEmulationMode) { From dd25a0cd4ca78d785211151ae3e6b4d95a2ba7ef Mon Sep 17 00:00:00 2001 From: Sarah Lensing Date: Mon, 21 Nov 2011 19:04:26 -0500 Subject: [PATCH 3/3] rounded corner on bg --- MTStatusBarOverlay.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MTStatusBarOverlay.m b/MTStatusBarOverlay.m index a8cbcb5..6d241ce 100755 --- a/MTStatusBarOverlay.m +++ b/MTStatusBarOverlay.m @@ -1308,6 +1308,11 @@ - (void)setColorSchemeForStatusBarStyle:(MTUIStatusBarStyle)style messageType:(M self.progressView.backgroundColor = kProgressViewBackgroundColor; self.progressView.image = nil; + + statusBarBackgroundImageView_.layer.masksToBounds = YES; + statusBarBackgroundImageView_.layer.cornerRadius = 5.0f; + statusBarBackgroundImageView_.layer.borderWidth = 1.0f; + } }