Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTUIStatusBarStyleCustom #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions MTStatusBarOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <UITableViewDataSource>

@interface MTStatusBarOverlay : UIWindow <UITableViewDataSource>
// only used if MTUIStatusBarStyleCustom:default is kDarkCustomThemeTextColor
@property (nonatomic, strong) UIColor *customThemeTextColor;
// only used if MTUIStatusBarStyleCustom:default is kDarkThemeErrorMessageTextColor
@property (nonatomic, strong) UIColor *customThemeErrorMessageTextColor;
// only used if MTUIStatusBarStyleCustom:default is kDarkThemeFinishedMessageTextColor
@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, strong) UIColor *customThemeDetailViewBackgroundColor;
// only used if MTUIStatusBarStyleCustom:default is kDarkThemeDetailViewBorderColor
@property (nonatomic, strong) UIColor *customThemeDetailViewBorderColor;
// only used if MTUIStatusBarStyleCustom:default is kDarkThemeHistoryTextColor
@property (nonatomic, strong) UIColor *customThemeHistoryTextColor;
// only used if MTUIStatusBarStyleCustom:default is [UIColor blackColor]
@property (nonatomic, strong) UIColor *customFinishBarBackgroundColor;
// only used if MTUIStatusBarStyleCustom:default is [UIColor blackColor]
@property (nonatomic, strong) UIColor *customFailBarBackgroundColor;
// only used if MTUIStatusBarStyleCustom:default is [UIColor blackColor]
@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)
@property (nonatomic, strong) UIView *backgroundView;
// the detailView is shown when animation is set to "FallDown"
Expand Down
96 changes: 84 additions & 12 deletions MTStatusBarOverlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -202,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
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -980,7 +1010,7 @@ - (void)setShrinked:(BOOL)shrinked animated:(BOOL)animated {
}

// update status bar background
[self setStatusBarBackgroundForStyle:[UIApplication sharedApplication].statusBarStyle];
[self setStatusBarBackgroundForStyle:statusBarStyle_];
}];
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1152,10 +1184,10 @@ - (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 (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];
Expand All @@ -1170,10 +1202,10 @@ - (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 (style == UIStatusBarStyleDefault && !IsIPad && !IsIPhoneEmulationMode) {
if (statusBarStyle_ == MTUIStatusBarStyleDefault && !IsIPad && !IsIPhoneEmulationMode) {
// set color of labels depending on messageType
switch(messageType) {
case MTMessageTypeFinish:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1241,6 +1273,46 @@ - (void)setColorSchemeForStatusBarStyle:(UIStatusBarStyle)style messageType:(MTM

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;

statusBarBackgroundImageView_.layer.masksToBounds = YES;
statusBarBackgroundImageView_.layer.cornerRadius = 5.0f;
statusBarBackgroundImageView_.layer.borderWidth = 1.0f;

}
}

Expand Down