Created
July 6, 2015 18:46
-
-
Save jonathan-beebe/0ea118409804252159dc to your computer and use it in GitHub Desktop.
Log all fonts & colors of view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void logFonts(UIView* view); | |
void logColors(UIView* view); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/jlawton/UIColor-HTMLColors | |
#import "UIColor+HTMLColors.h" | |
// https://github.com/robb/Underscore.m | |
#import "Underscore.h" | |
#define _ Underscore | |
NSMutableSet* findFonts(UIView* view) | |
{ | |
NSMutableSet* fonts = [NSMutableSet set]; | |
for (UIView* subview in view.subviews) { | |
if ([subview respondsToSelector:@selector(font)]) { | |
[fonts addObject:[subview performSelector:@selector(font)]]; | |
} | |
[fonts unionSet:findFonts(subview)]; | |
} | |
return fonts; | |
} | |
void logFonts(UIView* view) | |
{ | |
NSMutableSet* fonts = findFonts(view); | |
NSArray* sortedFonts = [[fonts allObjects] sortedArrayUsingComparator:^NSComparisonResult (UIFont* a, UIFont* b) { | |
return a.pointSize >= b.pointSize; | |
}]; | |
NSArray* boldFonts = _.array(sortedFonts).filter(^BOOL (UIFont* font) { | |
UIFontDescriptor* descriptor = font.fontDescriptor; | |
UIFontDescriptorSymbolicTraits traits = descriptor.symbolicTraits; | |
BOOL isBold = (traits & UIFontDescriptorTraitBold); | |
return isBold; | |
}).unwrap; | |
NSArray* regularFonts = _.array(sortedFonts).filter(^BOOL (UIFont* font) { | |
UIFontDescriptor* descriptor = font.fontDescriptor; | |
UIFontDescriptorSymbolicTraits traits = descriptor.symbolicTraits; | |
BOOL isBold = (traits & UIFontDescriptorTraitBold); | |
return !isBold; | |
}).unwrap; | |
NSLog(@"\n\nfound %li bold fonts %@\n\n", (unsigned long)boldFonts.count, boldFonts); | |
NSLog(@"\n\nfound %li regular fonts %@\n\n", (unsigned long)regularFonts.count, regularFonts); | |
} | |
#pragma mark - Colors | |
NSMutableSet* findColors(UIView* view) | |
{ | |
NSMutableSet* colors = [NSMutableSet set]; | |
UIColor* color; | |
for (UIView* subview in view.subviews) { | |
if ([subview respondsToSelector:@selector(backgroundColor)]) { | |
color = subview.backgroundColor; | |
if (color) | |
[colors addObject:color]; | |
} | |
if ([subview respondsToSelector:@selector(fillColor)]) { | |
color = [subview performSelector:@selector(fillColor)]; | |
if (color) | |
[colors addObject:color]; | |
} | |
if ([subview respondsToSelector:@selector(textColor)]) { | |
color = [subview performSelector:@selector(textColor)]; | |
if (color) | |
[colors addObject:color]; | |
} | |
[colors unionSet:findColors(subview)]; | |
} | |
return colors; | |
} | |
void logColors(UIView* view) | |
{ | |
NSSet* colors = findColors(view); | |
NSArray* cssColorStrings = _.array([colors allObjects]).map(^NSString* (UIColor* color) { | |
return [[color hexStringValue] lowercaseString]; | |
}).uniq.unwrap; | |
NSLog(@"\n\nfound %li colors %@\n\n", (unsigned long)cssColorStrings.count, cssColorStrings); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment