Add background and text color

This commit is contained in:
Pfeil, Scott Robert 2018-11-26 16:43:05 -05:00
parent f6793232b6
commit 79aaae2ad7
4 changed files with 35 additions and 1 deletions

View File

@ -6,7 +6,7 @@
// Copyright © 2016 Verizon Wireless. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <MVMCore/MVMCoreTopAlertDelegateProtocol.h>
extern NSUInteger const TopAlertDismissTime;
@ -44,6 +44,10 @@ extern NSUInteger const TopAlertDismissTime;
// If 0, uses default 5 seconds.
@property (nonatomic) NSInteger topAlertDismissTime;
// Server can set color.
@property (nullable, strong, nonatomic) UIColor *backgroundColor;
@property (nullable, strong, nonatomic) UIColor *textColor;
- (nullable instancetype)initWithResponseInfo:(nullable NSDictionary *)responseInfo;
- (nullable instancetype)initWithType:(nullable NSString *)type message:(nullable NSString *)message;

View File

@ -8,9 +8,11 @@
#import "MVMCoreTopAlertObject.h"
#import <MVMCore/NSDictionary+MFConvenience.h>
#import "MVMCoreGetterUtility.h"
#import "MVMCoreAlertHandler.h"
#import "MVMCoreJSONConstants.h"
NSUInteger const TopAlertDismissTime = 5;
@implementation MVMCoreTopAlertObject
@ -27,6 +29,15 @@ NSUInteger const TopAlertDismissTime = 5;
self.topMessage = [responseInfo string:KeyTopMessage];
self.imageNameOrURL = [responseInfo string:@"topAlertImageUrl"];
NSString *color = [responseInfo string:@"topAlertColor"];
if (color) {
self.backgroundColor = [MVMCoreGetterUtility getColorForHexString:color];
}
color = [responseInfo string:@"messageColor"];
if (color) {
self.textColor = [MVMCoreGetterUtility getColorForHexString:color];
}
// The default is yes if not sent by server (for legacy to work as is)
NSNumber *closeButton = [responseInfo objectForKey:KeyCloseButton ofType:[NSNumber class]];
if (closeButton) {

View File

@ -21,4 +21,8 @@
// Returns true if the user's language is Spanish
+ (BOOL)userPrefersSpanish;
// Returns a UIColor
+ (nonnull UIColor *)getColorForHexString:(nonnull NSString *)hexString;
@end

View File

@ -34,5 +34,20 @@
}
}
+ (nonnull UIColor *)getColorForHexString:(nonnull NSString *)hexString {
unsigned int hexint = 0;
// Create scanner
NSScanner *scanner = [NSScanner scannerWithString:hexString];
// Tell scanner to skip the # character
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"#"]];
[scanner scanHexInt:&hexint];
return [UIColor colorWithRed:((CGFloat) ((hexint & 0xFF0000) >> 16))/255
green:((CGFloat) ((hexint & 0xFF00) >> 8))/255
blue:((CGFloat) (hexint & 0xFF))/255
alpha:1];
}
@end