mvm_core_ui/MVMCoreUI/Styles/MFStyler.m
Pfeil, Scott Robert 98fa47aaae Migration
2019-01-10 14:23:14 -05:00

1341 lines
46 KiB
Objective-C

//
// MFStyler.m
// myverizon
//
// Created by Scott Pfeil on 11/26/14.
// Copyright (c) 2014 Verizon Wireless. All rights reserved.
//
#import "MFStyler.h"
#import "MFFonts.h"
#import "MFSizeObject.h"
#import "UIColor+MVMCoreUIConvenience.h"
#import "NSLayoutConstraint+MVMCoreUIConvenience.h"
#import "MVMCoreUISplitViewController.h"
CGFloat const PaddingDefault = 24;
CGFloat const PaddingDefaultHorizontalSpacing = 32;
CGFloat const PaddingDefaultVerticalSpacing = 32;
CGFloat const PaddingBetweenFields = 24;
CGFloat const PaddingHorizontalHeadlineWhiteView = 60;
CGFloat const PaddingHorizontalLarge = 72;
CGFloat const PaddingVerticalWhiteGrayView = 72;
CGFloat const PaddingVerticalHeadlineAlternate = 48;
CGFloat const PaddingPrimaryButtonTop = 36;
CGFloat const PaddingOne = 6;
CGFloat const PaddingTwo = 12;
CGFloat const PaddingThree = 18;
CGFloat const PaddingFour = 24;
CGFloat const PaddingFive = 30;
CGFloat const PaddingSix = 36;
CGFloat const PaddingSeven = 42;
CGFloat const PaddingEight = 48;
CGFloat const PaddingNine = 54;
CGFloat const PaddingTen = 60;
CGFloat const TableCellParagraphSpace = 3.f;
CGFloat const FooterLabelParagraphSpace = 4.f;
CGFloat const WebViewInset = 8.f;
CGFloat const HeightTableSeperatorHeight = 1;
CGFloat const MFHeightForSwitch = 22;
CGFloat const MFWidthForSwitch = 42;
CGFloat const DisableOppacity = 0.5;
CGFloat const PaymentMethodViewHeightWidthMultiplier = 0.55;
CGFloat const MinCellHeight = 96;
CGFloat const HeightIphone5 = 568;
CGFloat const DefaultOptionCellHeight = 120.0;
CGFloat const PromoViewHeight = 41.9;
CGFloat const LabelWithInternalButtonLineSpace = 2;
@implementation MFStyler
+ (CGFloat)splitTextFieldWidth {
return [MFStyler splitTextFieldWidthForViewWidth:[MVMCoreUISplitViewController getDetailViewWidth]];
}
+ (CGFloat)splitTextFieldWidthForViewWidth:(CGFloat) width {
return (width - PaddingOne)/2 - [MFStyler defaultHorizontalPaddingForApplicationWidth];
}
+ (nullable MFSizeObject *)sizeObjectGenericForCurrentDevice:(CGFloat)size {
MFSizeObject *sizeObject = [MFSizeObject sizeObjectWithStandardSize:size standardiPadPortraitSize:size * 1.3];
[sizeObject addLargerThanCustomSize:size * 1.4 forThreshold:MFSizeStandardiPadLandscapeThreshold];
[sizeObject addLargerThanCustomSize:size * 1.5 forThreshold:MFSizeiPadProLandscapeThreshold];
return sizeObject;
}
+ (CGFloat)sizeFontGenericForCurrentDevice:(CGFloat)size {
return [[MFStyler sizeObjectGenericForCurrentDevice:size] getValueBasedOnApplicationWidth];
}
#pragma mark - Spacing Defaults
+ (CGFloat)defaultHorizontalPaddingForApplicationWidth {
return [[MFSizeObject sizeObjectWithScalingStandardSize:PaddingDefaultHorizontalSpacing] getValueBasedOnApplicationWidth];
}
+ (CGFloat)defaultVerticalPaddingForApplicationWidth {
return [[MFSizeObject sizeObjectWithScalingStandardSize:PaddingDefaultVerticalSpacing] getValueBasedOnApplicationWidth];
}
+ (CGFloat)defaultHorizontalPaddingForSize:(CGFloat)size {
return [[MFSizeObject sizeObjectWithScalingStandardSize:PaddingDefaultHorizontalSpacing] getValueBasedOnSize:size];
}
+ (CGFloat)defaultVerticalPaddingForSize:(CGFloat)size {
return [[MFSizeObject sizeObjectWithScalingStandardSize:PaddingDefaultVerticalSpacing] getValueBasedOnSize:size];
}
#pragma mark - 2.0 fonts
+ (nullable UIFont *)fontH1:(BOOL)genericScaling {
CGFloat size = 40;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontH1 {
return [self fontH1:YES];
}
+ (nullable UIFont *)fontH2:(BOOL)genericScaling {
CGFloat size = 25;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontH2 {
return [self fontH2:YES];
}
+ (nullable UIFont *)fontH3:(BOOL)genericScaling {
CGFloat size = 18;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontH3 {
return [self fontH3:YES];
}
#pragma mark - Fonts
+ (nullable UIFont *)fontForHeadlineWithSize:(CGFloat)size genericScaling:(BOOL)genericScaling {
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForPlan:(BOOL)genericScaling {
CGFloat size = 100;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForBiggerHeadLine:(BOOL)genericScaling {
CGFloat size = 48;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForLoyaltySignUpHeadLine:(BOOL)genericScaling {
CGFloat size = 26;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForFeedHeadline:(BOOL)genericScaling {
CGFloat size = 32;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForFeedMessage:(BOOL)genericScaling {
CGFloat size = 20;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForFeedSubMessage:(BOOL)genericScaling {
CGFloat size = 11;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForHeadlineSmall:(BOOL)genericScaling {
CGFloat size = 15;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForHeadlineSmall2:(BOOL)genericScaling {
CGFloat size = 16;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForHeadlineSmall2ForWidth:(CGFloat)size {
CGFloat pointSize = 16;
pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size];
return [MFFonts mfFont75Bd:pointSize];
}
+ (nullable UIFont *)fontForHeadlineLarge:(BOOL)genericScaling {
CGFloat size = 40;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForHeadlineExtraLarge:(BOOL)genericScaling {
CGFloat size = 36;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)commonLabelB1:(BOOL)genericScaling {
CGFloat size = 13;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontB1ForWidth:(CGFloat)size {
CGFloat pointSize = 13;
pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size];
return [MFFonts mfFont75Bd:pointSize];
}
+ (nullable UIFont *)fontForSubheadBold:(BOOL)genericScaling {
CGFloat size = 14;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForSubheadBoldLarge:(BOOL)genericScaling {
CGFloat size = 20;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontB2:(BOOL)genericScaling {
CGFloat size = 13;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForBodyWithSize:(CGFloat)size genericScaling:(BOOL)genericScaling {
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontB2ForWidth:(CGFloat)size {
CGFloat pointSize = 13;
pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size];
return [MFFonts mfFont55Rg:pointSize];
}
+ (nullable UIFont *)fontForBodyWithSize:(CGFloat)size forWidth:(CGFloat)width {
size = [[MFStyler sizeObjectGenericForCurrentDevice:size] getValueBasedOnSize:width];
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontforChatText:(BOOL)genericScaling {
CGFloat size = 14;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForAccountLandingGreeting:(BOOL)genericScaling {
CGFloat size = 16;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForBodyLarge:(BOOL)genericScaling {
CGFloat size = 20;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForBodyBold:(BOOL)genericScaling {
CGFloat size = 13;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontB3:(BOOL)genericScaling {
CGFloat size = 11;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForProgressBarBottomLabel:(BOOL)genericScaling {
CGFloat size = 10;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontB1:(BOOL)genericScaling {
CGFloat size = 13;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForPrimaryButton:(BOOL)genericScaling {
CGFloat size = 14;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForPrimaryButtonForWidth:(CGFloat)size {
CGFloat pointSize = 14;
pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size];
return [MFFonts mfFont75Bd:pointSize];
}
+ (nullable UIFont *)fontForSmallButton:(BOOL)genericScaling {
CGFloat size = 11;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForSmallButtonForWidth:(CGFloat)size {
CGFloat pointSize = 11;
pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size];
return [MFFonts mfFont75Bd:pointSize];
}
+ (nullable UIFont *)fontForTextField:(BOOL)genericScaling {
CGFloat size = 16;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForTextFieldUnderLabel:(BOOL)genericScaling {
CGFloat size = 12;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForUnreadMessageOnSupport:(BOOL)genericScaling {
CGFloat size = 10;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForHeadlineAlternative:(BOOL)genericScaling {
CGFloat size = 24;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForHeadlineAlternativeForWidth:(CGFloat)size {
CGFloat pointSize = 24;
pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size];
return [MFFonts mfFont55Rg:pointSize];
}
+ (nullable UIFont *)fontH255:(BOOL)genericScaling {
CGFloat size = 25;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForFeedCardTitle:(BOOL)genericScaling {
CGFloat size = 16;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontB4:(BOOL)genericScaling {
CGFloat size = 14;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForSupportQuestionMark:(BOOL)genericScaling {
CGFloat size = 18;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForSupportDateStamp:(BOOL)genericScaling {
CGFloat size = 11;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForProgressBarTopLabel:(BOOL)genericScaling {
CGFloat size = 10;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForPlanCardTitle:(BOOL)genericScaling {
CGFloat size = 20;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForAccesseriesHeadline:(BOOL)genericScaling {
CGFloat size = 18.0;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForLargeLoyaltyHeaderTitle:(BOOL)genericScaling {
CGFloat size = 60;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForLoyaltyTitleSmall:(BOOL)genericScaling {
CGFloat size = 42;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForLoyaltyMessage:(BOOL)genericScaling {
CGFloat size = 20;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont55Rg:size];
}
+ (nullable UIFont *)fontForPtPCard:(BOOL)genericScaling {
CGFloat size = 22;
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontForLabelWithTopLeftCircleWithSize:(CGFloat)size genericScaling:(BOOL)genericScaling {
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFont75Bd:size];
}
+ (nullable UIFont *)fontOcratxtWitSize:(CGFloat)size genericScaling:(BOOL)genericScaling {
if (genericScaling) {
size = [self sizeFontGenericForCurrentDevice:size];
}
return [MFFonts mfFontOcratxt:size];
}
+ (nullable UIFont *)fontForPlan {
return [self fontForPlan:YES];
}
+ (nullable UIFont *)fontForBiggerHeadline {
return [self fontForBiggerHeadLine:YES];
}
+ (nullable UIFont *)fontForLoyaltySignUpHeadLine {
return [self fontForLoyaltySignUpHeadLine:YES];
}
+ (nullable UIFont *)fontForFeedHeadline {
return [self fontForFeedHeadline:YES];
}
+ (nullable UIFont *)fontForFeedMessage {
return [self fontForFeedMessage:YES];
}
+ (nullable UIFont *)fontForFeedSubMessage {
return [self fontForFeedSubMessage:YES];
}
+ (nullable UIFont *)fontForHeadlineSmall {
return [self fontForHeadlineSmall:YES];
}
+ (nullable UIFont *)fontForHeadlineTiny {
return [MFFonts mfFont75Bd:11];
}
+ (nullable UIFont *)fontForHeadlineSmall2 {
return [self fontForHeadlineSmall2:YES];
}
+ (nullable UIFont *)fontForHeadlineLarge {
return [self fontForHeadlineLarge:YES];
}
+ (nullable UIFont *)fontForHeadlineExtraLarge {
return [self fontForHeadlineExtraLarge:YES];
}
+ (nullable UIFont *)fontForSubheadBold {
return [self fontForSubheadBold:YES];
}
+ (nullable UIFont *)fontForSubheadBoldLarge {
return [self fontForSubheadBoldLarge:YES];
}
+ (nullable UIFont *)fontB2 {
return [self fontB2:YES];
}
+ (nullable UIFont *)fontforChatText {
return [self fontforChatText:NO];
}
+ (nullable UIFont *)fontForAccountLandingGreeting {
return [self fontForAccountLandingGreeting:YES];
}
+ (nullable UIFont *)fontForBodyLarge {
return [self fontForBodyLarge:YES];
}
+ (nullable UIFont *)fontForBodyBold {
return [self fontForBodyBold:YES];
}
+ (nullable UIFont *)fontB3 {
return [self fontB3:YES];
}
+ (nullable UIFont *)fontForProgressBarBottomLabel {
return [self fontForProgressBarBottomLabel:YES];
}
+ (nullable UIFont *)fontB1 {
return [self fontB1:YES];
}
+ (nullable UIFont *)fontForPrimaryButton {
return [self fontForPrimaryButton:YES];
}
+ (nullable UIFont *)fontForSmallButton {
return [self fontForSmallButton:YES];
}
+ (nullable UIFont *)fontForTextField {
return [self fontForTextField:YES];
}
+ (nullable UIFont *)fontForTextFieldUnderLabel {
return [self fontForTextFieldUnderLabel:YES];
}
+ (nullable UIFont *)fontForHeadlineAlternative {
return [self fontForHeadlineAlternative:YES];
}
+ (nullable UIFont *)fontForFeedCardTitle {
return [self fontForFeedCardTitle:YES];
}
+ (nullable UIFont *)fontB4 {
return [self fontB4:YES];
}
+ (nullable UIFont *)fontForSupportQuestionMark {
return [self fontForSupportQuestionMark:YES];
}
+ (nullable UIFont *)fontForSupportDateStamp {
return [self fontForSupportDateStamp:YES];
}
+ (nullable UIFont *)fontForProgressBarTopLabel {
return [self fontForProgressBarTopLabel:YES];
}
+ (nullable UIFont *)fontForPlanCardTitle {
return [self fontForPlanCardTitle:YES];
}
+ (nullable UIFont *)fontForAccesseriesHeadline {
return [self fontForAccesseriesHeadline:YES];
}
+ (nullable UIFont *)fontForLargeLoyaltyHeaderTitle {
return [self fontForLargeLoyaltyHeaderTitle:YES];
}
+ (nullable UIFont *)fontForLoyaltyTitleSmall {
return [self fontForLoyaltyTitleSmall:YES];
}
+ (nullable UIFont *)fontForLoyaltyMessage {
return [self fontForLoyaltyMessage:YES];
}
+ (nullable UIFont *)fontForUnreadMessageOnSupport {
return [self fontForUnreadMessageOnSupport:NO];
}
+ (nonnull UIFont *) boldFontForScaledSize:(CGFloat)size {
return [MFFonts mfFont75Bd:[self sizeFontGenericForCurrentDevice:size]];
}
+ (nonnull UIFont *) regularFontForScaledSize:(CGFloat)size {
return [MFFonts mfFont55Rg:[self sizeFontGenericForCurrentDevice:size]];
}
#pragma mark - 2.0 Styles
+ (void)styleLabelH1:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontH1:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelH1:(nonnull UILabel *)label {
[self styleLabelH1:label genericScaling:YES];
}
+ (void)styleLabelH2:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontH2:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelH2:(nonnull UILabel *)label {
[self styleLabelH2:label genericScaling:YES];
}
+ (void)styleLabelH3:(nonnull UILabel *)label {
label.font = [MFStyler fontH3];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelH3:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontH3:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelB1:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontB1:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelB2:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontB2:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelB2:(nonnull UILabel *)label size:(CGFloat)size genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForBodyWithSize:size genericScaling:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelB3:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontB3:genericScaling];
label.textColor = [UIColor mfBattleshipGrey];
}
+ (void)styleLabelB3:(nonnull UILabel *)label {
label.font = [MFStyler fontB3];
label.textColor = [UIColor mfBattleshipGrey];
}
+ (void)styleLabelB4:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontB4:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelB4:(nonnull UILabel *)label {
label.font = [MFStyler fontB4];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelTextStyle2:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontB2:genericScaling];
label.textColor = [UIColor mfBattleshipGrey];
}
+ (void)styleLabelTextStyle2:(nonnull UILabel *)label {
label.font = [MFStyler fontB2];
label.textColor = [UIColor mfBattleshipGrey];
}
+ (void)styleLabelFeedMessage:(nonnull UILabel *)label {
label.font = [MFStyler fontForFeedMessage];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelFeedSubMessage:(nonnull UILabel *)label {
label.font = [MFStyler fontForFeedMessage];
label.textColor = [UIColor blackColor];
}
#pragma mark - 1.0 Styles
+ (void)styleLabelHeadlineLarge:(nonnull UILabel *)label {
label.font = [MFStyler fontForHeadlineLarge];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelHeadlineExtraLarge:(nonnull UILabel *)label {
label.font = [MFStyler fontForHeadlineExtraLarge];
label.textColor = [UIColor mfRedColor];
}
+ (void)styleLabelHeadlineFeed:(nonnull UILabel *)label {
label.font = [MFStyler fontForFeedHeadline];
label.textColor = [UIColor mfRedColor];
}
+ (void)styleLabelSubheadBold:(nonnull UILabel *)label {
label.font = [MFStyler fontForSubheadBold];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelB2:(nonnull UILabel *)label {
label.font = [MFStyler fontB2];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelBodyLarge:(nonnull UILabel *)label {
label.font = [MFStyler fontForBodyLarge];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelBodyBold:(nonnull UILabel *)label {
label.font = [MFStyler fontForBodyBold];
label.textColor = [UIColor mfCharcoalColor];
}
+ (void)styleLabelBodyLighter:(nonnull UILabel *)label {
label.font = [MFStyler fontB2];
label.textColor = [UIColor mfGrayColor];
}
+ (void)styleLabelB1:(nonnull UILabel *)label {
label.font = [MFStyler fontB1];
label.textColor = [UIColor blackColor];
}
+ (void)styleFeedCardTitleLabel:(nonnull UILabel *)label {
label.font = [MFStyler fontForFeedCardTitle];
label.textColor = [UIColor blackColor];
}
+ (void)styleFeedCardTagLabel:(nonnull UILabel *)label {
label.font = [MFStyler fontB3];
label.textColor = [UIColor mfBrownishGrey];
}
+ (void)styleStandardSeparatorView:(nonnull UIView *)view {
[view setBackgroundColor:[UIColor mfBackgroundGray]];
}
+ (void)styleLabelHeadlineSmall:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForHeadlineSmall:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelHeadlineLarge:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForHeadlineLarge:genericScaling];
label.textColor = [UIColor mfRedColor];
}
+ (void)styleLabelHeadlineExtraLarge:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForHeadlineExtraLarge:genericScaling];
label.textColor = [UIColor mfRedColor];
}
+ (void)styleLabelHeadlineFeed:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForFeedHeadline:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelFeedMessage:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForFeedMessage:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelFeedSubMessage:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForFeedSubMessage:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelH2:(nonnull UILabel *)label size:(CGFloat)size genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForHeadlineWithSize:size genericScaling:genericScaling];
label.textColor = [UIColor mfRedColor];
}
+ (void)styleLabelHeadlineBlack:(nonnull UILabel *)label size:(CGFloat)size genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForHeadlineWithSize:size genericScaling:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelSubheadBold:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForSubheadBold:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelSubheadBoldLarge:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForSubheadBoldLarge:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelBodyLarge:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForBodyLarge:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleLabelBodyBold:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForBodyBold:genericScaling];
label.textColor = [UIColor mfCharcoalColor];
}
+ (void)styleLabelBodyLighter:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontB2:genericScaling];
label.textColor = [UIColor mfGrayColor];
}
+ (void)styleFeedCardTitleLabel:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontForFeedCardTitle:genericScaling];
label.textColor = [UIColor blackColor];
}
+ (void)styleFeedCardTagLabel:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling {
label.font = [MFStyler fontB3:genericScaling];
label.textColor = [UIColor mfBrownishGrey];
}
#pragma mark - Set Text With Styles
+ (void)styleSetLabelTextWithH2:(nonnull UILabel *)label text:(nullable NSString *)text {
[MFStyler styleLabelH2:label];
label.text = text;
}
+ (void)styleSetLabelTextWithHeadlineLarge:(nonnull UILabel *)label text:(nullable NSString *)text {
[MFStyler styleLabelHeadlineLarge:label];
label.text = text;
}
+ (void)styleSetLabelTextWithHeadlineExtraLarge:(nonnull UILabel *)label text:(nullable NSString *)text {
[MFStyler styleLabelHeadlineExtraLarge:label];
label.text = text;
}
+ (void)styleSetLabelTextWithH3:(nonnull UILabel *)label text:(nullable NSString *)text {
[MFStyler styleLabelH3:label];
label.text = text;
}
+ (void)styleSetLabelTextWithB2:(nonnull UILabel *)label text:(nullable NSString *)text {
[MFStyler styleLabelB2:label];
label.text = text;
}
+ (void)styleSetLabelTextWithBodyBold:(UILabel *)label text:(NSString *)text {
[MFStyler styleLabelBodyBold:label];
label.text = text;
}
+ (void)styleSetLabelTextWithB3:(nonnull UILabel *)label text:(nullable NSString *)text {
[MFStyler styleLabelB3:label];
label.text = text;
}
#pragma mark - Attributed Strings
+ (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string font:(nonnull UIFont *)font color:(nonnull UIColor *)color {
NSAttributedString *attributedString = nil;
if (![string isEqual:[NSNull null]] && string.length > 0) {
attributedString = [[NSAttributedString alloc] initWithString:string attributes:@{
NSFontAttributeName:font,
NSForegroundColorAttributeName:color
}];
} else {
attributedString = [[NSAttributedString alloc] initWithString:@""];
}
return attributedString;
}
+ (nonnull NSAttributedString *)styleGetHeadlineAttributedString:(nullable NSString *)string {
return [MFStyler styleGetAttributedString:string font:[MFStyler fontH2] color:[UIColor mfRedColor]];
}
+ (nonnull NSAttributedString *)styleGetHeadlineLargeAttributedString:(nullable NSString *)string {
return [MFStyler styleGetAttributedString:string font:[MFStyler fontForHeadlineLarge] color:[UIColor mfRedColor]];
}
+ (nonnull NSAttributedString *)styleGetHeadlineExtraLargeAttributedString:(nullable NSString *)string {
return [MFStyler styleGetAttributedString:string font:[MFStyler fontForHeadlineExtraLarge] color:[UIColor mfRedColor]];
}
+ (nonnull NSAttributedString *)styleGetSubheadAttributedString:(nullable NSString *)string {
return [MFStyler styleGetAttributedString:string font:[MFStyler fontH3] color:[UIColor blackColor]];
}
+ (nonnull NSAttributedString *)styleGetBodyAttributedString:(nullable NSString *)string {
return [MFStyler styleGetAttributedString:string font:[MFStyler fontB2] color:[UIColor blackColor]];
}
+ (nonnull NSAttributedString *)styleGetDisabledBodyAttributedString:(nullable NSString *)string {
return [MFStyler styleGetAttributedString:string font:[MFStyler fontB2] color:[UIColor mfLighterGrayColor]];
}
+ (nonnull NSAttributedString *)styleGetBodyBoldAttributedString:(nullable NSString *)string {
return [MFStyler styleGetAttributedString:string font:[MFStyler fontForBodyBold] color:[UIColor mfCharcoalColor]];
}
+ (nonnull NSAttributedString *)styleGetLegalAttributedString:(nullable NSString *)string {
return [MFStyler styleGetAttributedString:string font:[MFStyler fontB3] color:[UIColor mfGrayColor]];
}
+ (nonnull NSAttributedString *)styleGetSubtitleAttributedString:(nullable NSString *)string {
return [MFStyler styleGetAttributedString:string font:[MFStyler fontB1] color:[UIColor blackColor]];
}
+ (nonnull NSAttributedString *)styleGetDisabledSubtitleAttributedString:(nullable NSString *)string {
return [MFStyler styleGetAttributedString:string font:[MFStyler fontB1] color:[UIColor mfLighterGrayColor]];
}
+ (nonnull NSAttributedString *)styleGetTopAlignedAttributeStringWithLeftString:(nullable NSString *)left centerString:(nonnull NSString *)center rightString:(nullable NSString *)right withCenterStringFontSize:(CGFloat)fontSize andColor:(nonnull UIColor *)color {
if (left == nil){
left = @"";
}
if (center == nil) {
center = @"";
}
if (right == nil){
right = @"";
}
NSString *text = [NSString stringWithFormat:@"%@%@%@",
left,
center,
right];
NSDictionary *attribs = @{
NSForegroundColorAttributeName:color,
};
NSMutableAttributedString *attributedText =
[[NSMutableAttributedString alloc] initWithString:text
attributes:attribs];
//center
NSRange centerRange = [text rangeOfString:center];
UIFont *centerFont = [MFFonts mfFont75Bd:fontSize];
CGFloat centerHeight = centerFont.capHeight;
[attributedText addAttributes:@{NSFontAttributeName:[MFFonts mfFont75Bd:fontSize]}
range:centerRange];
//left
NSRange leftRange = [text rangeOfString:left];
UIFont *leftFont = [MFFonts mfFont75Bd:fontSize*0.34];
CGFloat leftHeight = leftFont.capHeight;
[attributedText addAttributes:@{NSFontAttributeName:leftFont,
NSBaselineOffsetAttributeName: @(centerHeight - leftHeight)
}
range:leftRange];
//right
NSRange rightRange = NSMakeRange(centerRange.location+centerRange.length, right.length);
UIFont *rightFont = [MFFonts mfFont75Bd:fontSize*0.34];
CGFloat rightHeight = rightFont.capHeight;
[attributedText addAttributes:@{NSFontAttributeName:rightFont,
NSBaselineOffsetAttributeName: @(centerHeight - rightHeight)
}
range:rightRange];
return attributedText;
}
+ (nonnull NSAttributedString *)styleGetTopAlignedAttributeStringWithLeftStringRightTop:(nullable NSString *)left centerString:(nonnull NSString *)center rightString:(nullable NSString *)right withCenterStringFontSize:(CGFloat)fontSize andColor:(nonnull UIColor *)color {
if (left == nil){
left = @"";
}
if (center == nil) {
center = @"";
}
if (right == nil){
right = @"";
}
NSString *text = [NSString stringWithFormat:@"%@%@%@",
left,
center,
right];
NSDictionary *attribs = @{
NSForegroundColorAttributeName:color,
};
NSMutableAttributedString *attributedText =
[[NSMutableAttributedString alloc] initWithString:text
attributes:attribs];
//center
NSRange centerRange = [text rangeOfString:center];
UIFont *centerFont = [MFFonts mfFont75Bd:fontSize];
CGFloat centerHeight = centerFont.capHeight;
[attributedText addAttributes:@{NSFontAttributeName:[MFFonts mfFont75Bd:fontSize]}
range:centerRange];
//left
NSRange leftRange = [text rangeOfString:left];
UIFont *leftFont = [MFFonts mfFont75Bd:fontSize*0.34];
CGFloat leftHeight = leftFont.capHeight;
[attributedText addAttributes:@{NSFontAttributeName:leftFont,
NSBaselineOffsetAttributeName: @(centerHeight - leftHeight)
}
range:leftRange];
//right
NSRange rightRange = NSMakeRange(centerRange.location+centerRange.length, right.length);
UIFont *rightFont = [MFFonts mfFont75Bd:fontSize*0.34];
[attributedText addAttributes:@{NSFontAttributeName:rightFont,
NSBaselineOffsetAttributeName: @(centerFont.pointSize - centerFont.capHeight + rightFont.pointSize/2)
}
range:rightRange];
return attributedText;
}
+ (void)styleGetAlignCenteredAttrituedString:(nullable NSMutableAttributedString *)string {
if (string.length > 0) {
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = NSTextAlignmentCenter;
[string addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];
}
}
+(NSAttributedString *)styleGetBoldStringWithFont:(UIFont *)inputFont fromString:(NSString *)inputString{
NSRange openingRange = [inputString rangeOfString:@"{"];
NSRange closingRange = [inputString rangeOfString:@"}"];
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:inputString];
if(openingRange.location!=NSNotFound && closingRange.location!=NSNotFound){
NSUInteger boldLength = closingRange.location-openingRange.location;
[attrString setAttributes:@{NSFontAttributeName:inputFont} range:NSMakeRange(openingRange.location,boldLength)];
[attrString replaceCharactersInRange:closingRange withString:@""];
[attrString replaceCharactersInRange:openingRange withString:@""];
}
return attrString;
}
+(NSString *)styleGetLowCaseSpace:(NSString *)inputString{
if (inputString.length>0) {
NSString *trimmedString = [[inputString lowercaseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
return trimmedString;
}else {
return @"";
}
}
#pragma mark - Gradient Colors
+ (nonnull NSArray *)gradientSpecialTicketGold {
return @[[UIColor colorWithRed:.72 green:.6 blue:.33 alpha:1],
[UIColor colorWithRed:1 green:.85 blue:.52 alpha:1],
[UIColor colorWithRed:1 green:.85 blue:.52 alpha:1],
[UIColor colorWithRed:1 green:.85 blue:.52 alpha:1],
[UIColor colorWithRed:.6 green:.42 blue:.07 alpha:1]];
}
+ (nonnull NSArray *)gradientSpecialTicketGoldCGColor {
return @[(id)[UIColor colorWithRed:.72 green:.6 blue:.33 alpha:1].CGColor,
(id)[UIColor colorWithRed:1 green:.85 blue:.52 alpha:1].CGColor,
(id)[UIColor colorWithRed:1 green:.85 blue:.52 alpha:1].CGColor,
(id)[UIColor colorWithRed:1 green:.85 blue:.52 alpha:1].CGColor,
(id)[UIColor colorWithRed:.6 green:.42 blue:.07 alpha:1].CGColor];
}
#pragma mark - Custom Styling Views
+ (void)styleView:(nonnull UIView *)view showMFViewBorder:(MFViewBorder)border withColor:(UIColor *)color borderLineWidth:(CGFloat)borderLineWidth borderLineLength:(CGFloat)borderLineLengh {
UIView *borderLine = [[UIView alloc]initWithFrame:CGRectZero];
borderLine.translatesAutoresizingMaskIntoConstraints = NO;
[view addSubview:borderLine];
switch (border) {
case MFViewBorderTop: {
[NSLayoutConstraint constraintPinSubview:borderLine pinTop:YES pinBottom:NO pinLeft:NO pinRight:NO];
[NSLayoutConstraint constraintPinView:borderLine heightConstraint:YES heightConstant:borderLineWidth widthConstraint:YES widthConstant:borderLineLengh];
[NSLayoutConstraint constraintPinSubview:borderLine pinCenterX:YES pinCenterY:NO];
break;
}
case MFViewBorderLeft: {
[NSLayoutConstraint constraintPinSubview:borderLine pinTop:NO pinBottom:NO pinLeft:YES pinRight:NO];
[NSLayoutConstraint constraintPinView:borderLine heightConstraint:YES heightConstant:borderLineLengh widthConstraint:YES widthConstant:borderLineWidth];
[NSLayoutConstraint constraintPinSubview:borderLine pinCenterX:NO pinCenterY:YES];
break;
}
case MFViewBorderBottom: {
[NSLayoutConstraint constraintPinSubview:borderLine pinTop:NO pinBottom:YES pinLeft:NO pinRight:NO];
[NSLayoutConstraint constraintPinView:borderLine heightConstraint:YES heightConstant:borderLineWidth widthConstraint:YES widthConstant:borderLineLengh];
[NSLayoutConstraint constraintPinSubview:borderLine pinCenterX:YES pinCenterY:NO];
break;
}
case MFViewBorderRight: {
[NSLayoutConstraint constraintPinSubview:borderLine pinTop:NO pinBottom:NO pinLeft:NO pinRight:YES];
[NSLayoutConstraint constraintPinView:borderLine heightConstraint:YES heightConstant:borderLineLengh widthConstraint:YES widthConstant:borderLineWidth];
[NSLayoutConstraint constraintPinSubview:borderLine pinCenterX:NO pinCenterY:YES];
break;
}
default:
break;
}
borderLine.backgroundColor = color;
}
+ (void)styleTextField:(nonnull UITextField *)textField {
textField.font = [MFStyler fontForTextField];
// As per AKQA
/* If the length of the text field exceeds the amount of space, the size of the text drops down.
So, the entire line of copy can be read.
16 point font size is the lowest recommended size.
*/
textField.minimumFontSize = 16;
textField.adjustsFontSizeToFitWidth = YES;// default is NO. if YES, text will shrink to minFontSize along baseline
}
+ (UIImage *)grayscaleImage:(UIImage *)image {
UIGraphicsBeginImageContextWithOptions(image.size, YES, 1.0);
CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
// Draw the image with the luminosity blend mode.
// On top of a white background, this will give a black and white image.
[image drawInRect:imageRect blendMode:kCGBlendModeLuminosity alpha:1.0];
// Get the resulting image.
UIImage *filteredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return filteredImage;
}
+(void)setGradientToLabel:(nonnull UILabel*)label withColors:(nonnull NSArray*)colors {
CGSize textSize = [label.text sizeWithAttributes: @{NSBaselineOffsetAttributeName : @0,
NSFontAttributeName: [UIFont fontWithName:label.font.fontName size:label.font.lineHeight]}];
CGFloat width = textSize.width > 1024 ? 1024 : textSize.width; // max 1024 due to Core Graphics limitations
CGFloat height = textSize.height > 1024 ? 1024 : textSize.height; // max 1024 due to Core Graphics limitations
// create a new bitmap image context
UIGraphicsBeginImageContext(CGSizeMake(width, height));
// get context
CGContextRef context = UIGraphicsGetCurrentContext();
// push context to make it current (need to do this manually because we are not drawing in a UIView)
UIGraphicsPushContext(context);
//draw gradient
CGGradientRef glossGradient;
CGColorSpaceRef rgbColorspace;
size_t num_locations = colors.count;
CGFloat locations[colors.count];
CGFloat components[colors.count * 4];
int componentIndex = 0;
for (int i = 0; i < colors.count; i++) {
locations[i] = (1.0/(float)colors.count) * i;
UIColor *color = colors[i];
const CGFloat* colorComponents = CGColorGetComponents(color.CGColor);
for (int component = 0; component < 4; component++) {
components[componentIndex] = colorComponents[component];
componentIndex++;
}
}
rgbColorspace = CGColorSpaceCreateDeviceRGB();
glossGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
CGPoint topCenter = CGPointMake(0, 0);
CGPoint bottomCenter = CGPointMake(textSize.width,0);
CGContextDrawLinearGradient(context, glossGradient, topCenter, bottomCenter, 0);
CGGradientRelease(glossGradient);
CGColorSpaceRelease(rgbColorspace);
// pop context
UIGraphicsPopContext();
// get a UIImage from the image context
UIImage *gradientImage = UIGraphicsGetImageFromCurrentImageContext();
// clean up drawing environment
UIGraphicsEndImageContext();
label.textColor = [UIColor colorWithPatternImage:gradientImage];
}
+(NSDictionary *)labelStrokeAttributes:(UIColor*)color {
return @{NSStrokeColorAttributeName : color,
NSStrokeWidthAttributeName : @-1.0};
}
+ (void)mfStyleBlackPageControl:(UIPageControl *)pageControl {
pageControl.pageIndicatorTintColor = [UIColor mfLighterGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
}
+ (void)mfStylePageControl:(UIPageControl *)pageControl {
pageControl.pageIndicatorTintColor = [UIColor mfLighterGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor mfRedColor];
}
+ (NSString *)getCountTime:(NSInteger)leftTime timeformat:(NSString *)timeFormat timeUnit:(MFTimeFormatUnit)timeUnit timeSuffix:(NSString *)suffix {
int seconds = leftTime % 60;
int minutes = (leftTime / 60) % 60;
int hours = (leftTime / 3600) % 24;
long days = (leftTime / 86400);
NSArray *times = [timeFormat componentsSeparatedByString:@":"];
NSMutableString *timeString = [NSMutableString new];
if ([times containsObject:@"DD"]) {
[timeString appendString:[NSString stringWithFormat:@"%02ld",days]];
if (timeUnit == MFTimeFormatNormal) {
NSString *dayUnit = (days <= 1) ? @" day": @" days";
[timeString appendString:dayUnit];
} else if (timeUnit == MFTimeFormatColon && ![[times lastObject] isEqualToString:@"DD"]) {
[timeString appendString:@" : "];
}
if (![[times lastObject] isEqualToString:@"DD"] && suffix) {
[timeString appendString:suffix];
}
}
if ([times containsObject:@"HH"]) {
if (![times containsObject:@"DD"]) {
hours = (int)(leftTime / 3600);
}
[timeString appendString:[NSString stringWithFormat:@"%02d",hours]];
if (timeUnit == MFTimeFormatNormal) {
NSString *hourUnit = (hours <= 1) ? @" hour": @" hours";
[timeString appendString:hourUnit];
} else if (timeUnit == MFTimeFormatColon && ![[times lastObject] isEqualToString:@"HH"]) {
[timeString appendString:@" : "];
}
if (![[times lastObject] isEqualToString:@"HH"] && suffix) {
[timeString appendString:suffix];
}
}
if ([times containsObject:@"MM"]) {
if (![times containsObject:@"HH"]) {
if (![times containsObject:@"DD"]) {
minutes = (int)(leftTime / 60);
} else {
minutes = (int)((leftTime - days * 86400) / 60);
}
}
[timeString appendString:[NSString stringWithFormat:@"%02d",minutes]];
if (timeUnit == MFTimeFormatNormal) {
NSString *minuteUnit = (minutes <= 1) ? @" min": @" mins";
[timeString appendString:minuteUnit];
} else if (timeUnit == MFTimeFormatColon && ![[times lastObject] isEqualToString:@"MM"]) {
[timeString appendString:@" : "];
}
if (![[times lastObject] isEqualToString:@"MM"] && suffix) {
[timeString appendString:suffix];
}
}
if ([times containsObject:@"SS"]) {
if (![times containsObject:@"MM"]) {
if (![times containsObject:@"HH"]) {
if (![times containsObject:@"DD"]) {
seconds = (int)leftTime;
} else {
seconds = (int)(leftTime % 86400);
}
} else {
seconds = (int)(leftTime % 3600);
}
}
[timeString appendString:[NSString stringWithFormat:@"%02d",seconds]];
if (timeUnit == MFTimeFormatNormal) {
NSString *secondUnit = (seconds <= 1) ? @" sec": @" secs";
[timeString appendString:secondUnit];
}
}
return timeString;
}
@end