Number convenience for NSDictionary category
KeyTextColor constant for MFLabel and core ui Checker for hasText on MFLabel update molecule protocol for mf label. separator use molecule protocol fix to header
This commit is contained in:
parent
f243d201b6
commit
25c754b234
@ -8,6 +8,7 @@
|
||||
|
||||
#import "PrimaryButton.h"
|
||||
#import <MVMCoreUI/MFSizeObject.h>
|
||||
#import <MVMCoreUI/MVMCoreUIConstants.h>
|
||||
#import "MVMCoreUISplitViewController.h"
|
||||
#import "MFStyler.h"
|
||||
#import "UIColor+MFConvenience.h"
|
||||
@ -566,7 +567,7 @@
|
||||
self.primaryButtonType = PrimaryButtonTypeCustom;
|
||||
NSString *color = [json string:@"fillColor"];
|
||||
self.fillColor = (color ? [UIColor mfGetColorForHex:color] : nil);
|
||||
color = [json string:@"textColor"];
|
||||
color = [json string:KeyTextColor];
|
||||
self.textColor = (color ? [UIColor mfGetColorForHex:color] : nil);
|
||||
color = [json string:@"borderColor"];
|
||||
self.borderColor = (color ? [UIColor mfGetColorForHex:color] : nil);
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#import <MVMCoreUI/MFView.h>
|
||||
@class MFSizeObject;
|
||||
|
||||
@interface MFLabel : UILabel <MVMCoreViewProtocol>
|
||||
@interface MFLabel : UILabel <MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol>
|
||||
|
||||
- (nullable instancetype)initWithStandardFontSize:(CGFloat)size;
|
||||
|
||||
@ -23,6 +23,9 @@
|
||||
// Set the font and set to scale
|
||||
- (void)setFont:(nonnull UIFont *)font scale:(BOOL)scale;
|
||||
|
||||
// Convenience checker for text or attributed text.
|
||||
- (BOOL)hasText;
|
||||
|
||||
#pragma mark - 2.0
|
||||
|
||||
+ (nonnull MFLabel *)commonLabelB2:(BOOL)scale;
|
||||
|
||||
@ -7,23 +7,60 @@
|
||||
//
|
||||
|
||||
#import "MFLabel.h"
|
||||
#import "MFStyler.h"
|
||||
#import <MVMCoreUI/MFStyler.h>
|
||||
#import <MVMCoreUI/MFSizeObject.h>
|
||||
#import <MVMCoreUI/MVMCoreUIConstants.h>
|
||||
#import "UIColor+MFConvenience.h"
|
||||
#import "MFFonts.h"
|
||||
#import "MVMCoreUISplitViewController.h"
|
||||
@import MVMCore.MVMCoreGetterUtility;
|
||||
@import MVMCore.NSDictionary_MFConvenience;
|
||||
@import MVMCore.MVMCoreJSONConstants;
|
||||
|
||||
@interface MFLabel ()
|
||||
|
||||
@property (strong, nonatomic) NSNumber *scaleSize;
|
||||
|
||||
// Used for scaling the font in updateView.
|
||||
@property (strong, nonatomic) NSAttributedString *originalAttributedString;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MFLabel
|
||||
|
||||
- (instancetype)initWithStandardFontSize:(CGFloat)size {
|
||||
- (void)setupView {
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.numberOfLines = 0;
|
||||
self.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self styleB2:YES];
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
[self setupView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super initWithCoder:coder];
|
||||
if (self) {
|
||||
[self setupView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self setupView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithStandardFontSize:(CGFloat)size {
|
||||
if ([self init]) {
|
||||
self.standardFontSize = size;
|
||||
}
|
||||
return self;
|
||||
@ -31,7 +68,16 @@
|
||||
|
||||
- (void)updateView:(CGFloat)size {
|
||||
self.scaleSize = @(size);
|
||||
if (!fequal(self.standardFontSize, 0)) {
|
||||
if (self.originalAttributedString) {
|
||||
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:self.originalAttributedString];
|
||||
[attributedString removeAttribute:NSFontAttributeName range:NSMakeRange(0, attributedString.length)];
|
||||
[self.originalAttributedString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, self.originalAttributedString.length) options:0 usingBlock:^(UIFont *value, NSRange range, BOOL * _Nonnull stop) {
|
||||
// Loop the original attributed string, resize the fonts.
|
||||
UIFont *font = [value fontWithSize:[[MFStyler sizeObjectGenericForCurrentDevice:value.pointSize] getValueBasedOnSize:size]];
|
||||
[attributedString addAttribute:NSFontAttributeName value:font range:range];
|
||||
}];
|
||||
self.attributedText = attributedString;
|
||||
} else if (!fequal(self.standardFontSize, 0)) {
|
||||
MFSizeObject *sizeObject = self.sizeObject;
|
||||
if (!sizeObject) {
|
||||
sizeObject = [MFStyler sizeObjectGenericForCurrentDevice:self.standardFontSize];
|
||||
@ -56,13 +102,12 @@
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
- (BOOL)hasText {
|
||||
return self.text.length > 0 || self.attributedText.length > 0;
|
||||
}
|
||||
|
||||
+ (nonnull MFLabel *)label {
|
||||
MFLabel *label = [[MFLabel alloc] initWithFrame:CGRectZero];
|
||||
label.backgroundColor = [UIColor clearColor];
|
||||
label.numberOfLines = 0;
|
||||
label.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
label.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
return label;
|
||||
return [[MFLabel alloc] initWithFrame:CGRectZero];
|
||||
}
|
||||
|
||||
+ (nonnull MFLabel *)commonLabelB2:(BOOL)scale {
|
||||
@ -193,6 +238,72 @@
|
||||
|
||||
#pragma mark - Setters
|
||||
|
||||
+ (void)setUILabel:(nullable UILabel *)label withJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData {
|
||||
if (label) {
|
||||
label.text = [json string:KeyText];
|
||||
NSString *textColor = [json string:KeyTextColor];
|
||||
if (textColor) {
|
||||
label.textColor = [UIColor mfGetColorForHex:textColor];
|
||||
}
|
||||
NSString *backgroundColor = [json string:KeyBackgroundColor];
|
||||
if (backgroundColor) {
|
||||
label.backgroundColor = [UIColor mfGetColorForHex:backgroundColor];
|
||||
}
|
||||
NSString *accessibilityText = [json string:@"accessibilityText"];
|
||||
if (accessibilityText) {
|
||||
label.accessibilityLabel = accessibilityText;
|
||||
}
|
||||
NSString *fontName = [json string:@"fontName"];
|
||||
NSNumber *fontSize = [json optionalNumberForKey:@"fontSize"];
|
||||
if (fontName) {
|
||||
label.font = [MFFonts mfFontWithName:fontName size:fontSize ? fontSize.doubleValue : label.font.pointSize];
|
||||
} else if (fontSize) {
|
||||
label.font = [label.font fontWithSize:fontSize.doubleValue];
|
||||
}
|
||||
|
||||
NSArray *attributes = [json array:@"attributes"];
|
||||
if (attributes) {
|
||||
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text attributes:@{NSFontAttributeName:label.font,NSForegroundColorAttributeName:label.textColor}];
|
||||
for (NSDictionary *attribute in attributes) {
|
||||
NSNumber *location = [attribute optionalNumberForKey:@"location"];
|
||||
NSNumber *length = [attribute optionalNumberForKey:@"length"];
|
||||
if (location && length) {
|
||||
NSRange range = NSMakeRange(location.unsignedIntegerValue, length.unsignedIntegerValue);
|
||||
NSString *type = [attribute string:KeyType];
|
||||
if ([type isEqualToString:@"underline"]) {
|
||||
[attributedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:range];
|
||||
} else if ([type isEqualToString:@"strikethrough"]) {
|
||||
[attributedString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleThick) range:range];
|
||||
} else if ([type isEqualToString:@"color"]) {
|
||||
NSString *color = [attribute string:KeyTextColor];
|
||||
if (color) {
|
||||
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor mfGetColorForHex:color] range:range];
|
||||
}
|
||||
} else if ([type isEqualToString:@"font"]) {
|
||||
NSString *fontName = [attribute string:@"name"];
|
||||
NSNumber *fontSize = [attribute optionalNumberForKey:@"size"];
|
||||
UIFont *font = nil;
|
||||
if (fontName) {
|
||||
font = [MFFonts mfFontWithName:fontName size:fontSize ? fontSize.doubleValue : label.font.pointSize];
|
||||
} else if (fontSize) {
|
||||
font = [label.font fontWithSize:fontSize.doubleValue];
|
||||
}
|
||||
if (font) {
|
||||
[attributedString addAttribute:NSFontAttributeName value:font range:range];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
label.attributedText = attributedString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setWithJSON:(NSDictionary *)json delegate:(NSObject *)delegate additionalData:(NSDictionary *)additionalData {
|
||||
[MFLabel setUILabel:self withJSON:json delegate:delegate additionalData:additionalData];
|
||||
self.originalAttributedString = self.attributedText;
|
||||
}
|
||||
|
||||
- (void)styleB2:(BOOL)scale {
|
||||
[MFStyler styleLabelB2:self genericScaling:NO];
|
||||
[self setScale:scale];
|
||||
|
||||
@ -8,8 +8,11 @@
|
||||
|
||||
#import "SeparatorView.h"
|
||||
#import <MVMCoreUI/MFSizeObject.h>
|
||||
#import <MVMCoreUI/MVMCoreUIConstants.h>
|
||||
#import "MVMCoreUICommonViewsUtility.h"
|
||||
#import "UIColor+MFConvenience.h"
|
||||
@import MVMCore.MVMCoreJSONConstants;
|
||||
@import MVMCore.NSDictionary_MFConvenience;
|
||||
|
||||
@interface SeparatorView()
|
||||
|
||||
@ -17,9 +20,6 @@
|
||||
|
||||
@implementation SeparatorView
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma mark - class methods
|
||||
|
||||
+ (nullable SeparatorView *)separatorAddToView:(nullable UIView *)superView position:(SeparatorPosition)position positionPadding:(CGFloat)positionPadding withHorizontalPadding:(CGFloat)padding {
|
||||
@ -95,6 +95,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setWithJSON:(NSDictionary *)json delegate:(NSObject *)delegate additionalData:(NSDictionary *)additionalData {
|
||||
[super setWithJSON:json delegate:delegate additionalData:additionalData];
|
||||
if (json) {
|
||||
self.hidden = NO;
|
||||
NSString *type = [json string:KeyType];
|
||||
if ([type isEqualToString:@"standard"]) {
|
||||
[self setSize:1];
|
||||
} else if ([type isEqualToString:@"medium"]) {
|
||||
[self setSize:2];
|
||||
} else if ([type isEqualToString:@"heavy"]) {
|
||||
[self setSize:4];
|
||||
}
|
||||
NSString *backgroundColor = [json string:KeyBackgroundColor];
|
||||
if (backgroundColor) {
|
||||
self.backgroundColor = [UIColor mfGetColorForHex:backgroundColor];
|
||||
}
|
||||
} else {
|
||||
self.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - helper
|
||||
|
||||
- (void)hide {
|
||||
@ -104,37 +125,37 @@
|
||||
self.hidden = NO;
|
||||
}
|
||||
|
||||
- (void)setAsHeavy {
|
||||
self.heightSizeObject.standardSize = 4;
|
||||
- (void)setSize:(CGFloat)size {
|
||||
self.heightSizeObject.standardSize = size;
|
||||
self.height.constant = [self.heightSizeObject getValueBasedOnScreenSize];
|
||||
}
|
||||
|
||||
- (void)setAsHeavy {
|
||||
[self setSize:4];
|
||||
self.backgroundColor = [UIColor blackColor];
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
}
|
||||
|
||||
- (void)setAsRegular {
|
||||
self.heightSizeObject.standardSize = 1;
|
||||
self.height.constant = [self.heightSizeObject getValueBasedOnScreenSize];
|
||||
[self setSize:1];
|
||||
self.backgroundColor = [UIColor blackColor];
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
}
|
||||
|
||||
- (void)setAsLight {
|
||||
self.heightSizeObject.standardSize = 1;
|
||||
self.height.constant = [self.heightSizeObject getValueBasedOnScreenSize];
|
||||
[self setSize:1];
|
||||
self.backgroundColor = [UIColor mfSilver];
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
}
|
||||
|
||||
- (void)setAsMedium {
|
||||
self.heightSizeObject.standardSize = 2;
|
||||
self.height.constant = [self.heightSizeObject getValueBasedOnScreenSize];
|
||||
[self setSize:2];
|
||||
self.backgroundColor = [UIColor blackColor];
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@ -164,7 +164,7 @@
|
||||
// If we are not loading from the cache, check if the server has provided an index to start with. (When loading from the cache, we use the requested pagetype and modules to find the tab)
|
||||
__block NSInteger currentIndex = NSNotFound;
|
||||
if (!self.loadObject.pageDataFromCache) {
|
||||
NSNumber *currentIndexNumber = [self.loadObject.pageJSON objectForKey:@"currentTabIndex" ofType:[NSNumber class]];
|
||||
NSNumber *currentIndexNumber = [self.loadObject.pageJSON optionalNumberForKey:@"currentTabIndex"];
|
||||
if (currentIndexNumber) {
|
||||
currentIndex = [currentIndexNumber integerValue];
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ public class MVMCoreUIHeaderView: ViewConstrainingView {
|
||||
headlineLabel.updateView(size)
|
||||
messageLabel.updateView(size)
|
||||
separatorView?.updateView(size)
|
||||
setSpacing()
|
||||
}
|
||||
|
||||
public override func setupView() {
|
||||
@ -74,6 +75,30 @@ public class MVMCoreUIHeaderView: ViewConstrainingView {
|
||||
}
|
||||
}
|
||||
|
||||
public func setSpacing() {
|
||||
if headlineLabel.hasText() && messageLabel.hasText() {
|
||||
spaceBetweenLabels?.constant = PaddingTwo
|
||||
show()
|
||||
} else if headlineLabel.hasText() || messageLabel.hasText() {
|
||||
spaceBetweenLabels?.constant = 0
|
||||
show()
|
||||
} else {
|
||||
hide()
|
||||
}
|
||||
}
|
||||
|
||||
public override func show() {
|
||||
super.show()
|
||||
heightConstraint?.isActive = false
|
||||
layoutIfNeeded()
|
||||
}
|
||||
|
||||
public override func hide() {
|
||||
super.hide()
|
||||
heightConstraint?.isActive = true
|
||||
layoutIfNeeded()
|
||||
}
|
||||
|
||||
public override func setLeftPinConstant(_ constant: CGFloat) {
|
||||
leftConstraintTitle?.constant = constant
|
||||
leftConstraintMessage?.constant = constant
|
||||
@ -88,10 +113,7 @@ public class MVMCoreUIHeaderView: ViewConstrainingView {
|
||||
|
||||
public override func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) {
|
||||
super.setWithJSON(json, delegate: delegate, additionalData: additionalData)
|
||||
headlineLabel.text = json?.optionalStringForKey(KeyTitle)
|
||||
messageLabel.text = json?.optionalStringForKey(KeyMessage)
|
||||
separatorView?.isHidden = !(json?.boolForKey("showSeparator") ?? false)
|
||||
if let colorString = json?.optionalStringForKey("backgroundColor") {
|
||||
if let colorString = json?.optionalStringForKey(KeyBackgroundColor) {
|
||||
backgroundColor = .mfGet(forHex: colorString)
|
||||
}
|
||||
if let colorString = json?.optionalStringForKey("contentColor") {
|
||||
@ -101,6 +123,13 @@ public class MVMCoreUIHeaderView: ViewConstrainingView {
|
||||
separatorView?.backgroundColor = color
|
||||
}
|
||||
|
||||
let headlineJSON = json?.optionalDictionaryForKey("headline")
|
||||
headlineLabel.setWithJSON(headlineJSON, delegate: delegate, additionalData: additionalData)
|
||||
let bodyJSON = json?.optionalDictionaryForKey("body")
|
||||
messageLabel.setWithJSON(bodyJSON, delegate: delegate, additionalData: additionalData)
|
||||
let separatorJSON = json?.optionalDictionaryForKey("separator")
|
||||
separatorView?.setWithJSON(separatorJSON, delegate: delegate, additionalData: additionalData)
|
||||
|
||||
if separatorView?.isHidden ?? true {
|
||||
bottomPin?.constant = 0
|
||||
} else {
|
||||
|
||||
@ -12,6 +12,10 @@ public class MVMCoreUIMoleculeStackView: MFView {
|
||||
var spacingBlock: ((Any) -> UIEdgeInsets)?
|
||||
var moleculesArray: [UIView]?
|
||||
|
||||
public override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
}
|
||||
|
||||
init(withJSON json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) {
|
||||
super.init(frame: CGRect.zero)
|
||||
setWithJSON(json, delegate: delegate, additionalData: additionalData)
|
||||
|
||||
@ -11,7 +11,7 @@ import UIKit
|
||||
public class MoleculeStackTemplate: ThreeLayerViewController {
|
||||
|
||||
|
||||
public override func spaceBetweenMiddleAndBottom() -> CGFloat? {
|
||||
public override func spaceBetweenTopAndMiddle() -> CGFloat? {
|
||||
return PaddingTwo
|
||||
}
|
||||
|
||||
|
||||
@ -15,5 +15,6 @@
|
||||
+ (nullable UIFont *)mfFont75Bd:(CGFloat)size;
|
||||
+ (nullable UIFont *)mfFont55Rg:(CGFloat)size;
|
||||
+ (nullable UIFont *)mfFontOcratxt:(CGFloat)size;
|
||||
+ (nullable UIFont *)mfFontWithName:(nonnull NSString *)name size:(CGFloat)size;
|
||||
|
||||
@end
|
||||
|
||||
@ -13,6 +13,15 @@
|
||||
|
||||
@implementation MFFonts
|
||||
|
||||
+ (void)loadMVMFonts {
|
||||
static dispatch_once_t once;
|
||||
dispatch_once(&once, ^{
|
||||
[MFFonts loadFont:@"NHaasGroteskDSStd-75Bd" type:@"otf"];
|
||||
[MFFonts loadFont:@"NHaasGroteskDSStd-55Rg" type:@"otf"];
|
||||
[MFFonts loadFont:@"OCRAExtended" type:@"ttf"];
|
||||
});
|
||||
}
|
||||
|
||||
+ (void)loadFont:(NSString *)fontName type:(NSString *)type{
|
||||
|
||||
NSString *fontPath = [[MVMCoreUIUtility bundleForMVMCoreUI] pathForResource:fontName ofType:type];
|
||||
@ -31,30 +40,22 @@
|
||||
}
|
||||
|
||||
+ (nullable UIFont *)mfFont75Bd:(CGFloat)size {
|
||||
NSString *fontName = @"NHaasGroteskDSStd-75Bd";
|
||||
static dispatch_once_t once;
|
||||
dispatch_once(&once, ^{
|
||||
[MFFonts loadFont:fontName type:@"otf"];
|
||||
});
|
||||
return [UIFont fontWithName:fontName size:size];
|
||||
[self loadMVMFonts];
|
||||
return [UIFont fontWithName:@"NHaasGroteskDSStd-75Bd" size:size];
|
||||
}
|
||||
|
||||
+ (nullable UIFont *)mfFont55Rg:(CGFloat)size {
|
||||
NSString *fontName = @"NHaasGroteskDSStd-55Rg";
|
||||
static dispatch_once_t once;
|
||||
dispatch_once(&once, ^{
|
||||
[MFFonts loadFont:fontName type:@"otf"];
|
||||
});
|
||||
return [UIFont fontWithName:fontName size:size];
|
||||
[self loadMVMFonts];
|
||||
return [UIFont fontWithName:@"NHaasGroteskDSStd-55Rg" size:size];
|
||||
}
|
||||
|
||||
+ (nullable UIFont *)mfFontOcratxt:(CGFloat)size {
|
||||
NSString *fontName = @"OCRAExtended";
|
||||
static dispatch_once_t once;
|
||||
dispatch_once(&once, ^{
|
||||
[MFFonts loadFont:fontName type:@"ttf"];
|
||||
});
|
||||
return [UIFont fontWithName:fontName size:size];
|
||||
[self loadMVMFonts];
|
||||
return [UIFont fontWithName:@"OCRAExtended" size:size];
|
||||
}
|
||||
|
||||
+ (nullable UIFont *)mfFontWithName:(nonnull NSString *)name size:(CGFloat)size {
|
||||
return [UIFont fontWithName:name size:size] ?: [self mfFont55Rg:size];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -28,6 +28,10 @@ extern NSString * const KeySecondaryButton;
|
||||
extern NSString * const KeyTitlePrefix;
|
||||
extern NSString * const KeyTitlePostfix;
|
||||
|
||||
extern NSString * const KeyBackgroundColor;
|
||||
extern NSString * const KeyText;
|
||||
extern NSString * const KeyTextColor;
|
||||
|
||||
#pragma mark - Values
|
||||
|
||||
extern NSString * const StringY;
|
||||
|
||||
@ -27,6 +27,10 @@ NSString * const KeySecondaryButton = @"SecondaryButton";
|
||||
NSString * const KeyTitlePrefix = @"titlePrefix";
|
||||
NSString * const KeyTitlePostfix = @"titlePostfix";
|
||||
|
||||
NSString * const KeyBackgroundColor = @"backgroundColor";
|
||||
NSString * const KeyText = @"text";
|
||||
NSString * const KeyTextColor = @"textColor";
|
||||
|
||||
#pragma mark - Values
|
||||
|
||||
NSString * const StringY = @"Y";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user