From 6d958802b271535ff570ef7364afba8053ca8fd0 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Mon, 25 Jun 2018 10:20:08 +0200 Subject: [PATCH] Using predefined colors --- MacPass/NSString+MPPrettyPasswordDisplay.m | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/MacPass/NSString+MPPrettyPasswordDisplay.m b/MacPass/NSString+MPPrettyPasswordDisplay.m index 5d10cc4f..7e652e28 100644 --- a/MacPass/NSString+MPPrettyPasswordDisplay.m +++ b/MacPass/NSString+MPPrettyPasswordDisplay.m @@ -7,6 +7,7 @@ // #import "NSString+MPPrettyPasswordDisplay.h" +#import "KeePassKit/KeePassKit.h" @implementation NSString (MPPrettyPasswordDisplay) @@ -19,20 +20,33 @@ } - (void)_setAttributesInString:(NSMutableAttributedString *)string { + static NSColor *blueColor; + static NSColor *orangeColor; + static NSColor *greenColor; + static NSColor *yellowColor; + + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + blueColor = [NSColor colorWithRed:0.3 green:0.7 blue:1 alpha:1]; + orangeColor = [NSColor colorWithRed:0.3 green:0.7 blue:1 alpha:1]; + greenColor = [NSColor colorWithRed:0.3 green:0.7 blue:1 alpha:1]; + yellowColor = [NSColor colorWithRed:0.3 green:0.7 blue:1 alpha:1]; + }); + /* digits */ NSArray *digitRanges = [self rangesOfCharactersInSet:NSCharacterSet.decimalDigitCharacterSet]; for(NSValue *rangeValue in digitRanges) { - [string addAttribute:NSForegroundColorAttributeName value:NSColor.redColor range:rangeValue.rangeValue]; + [string addAttribute:NSForegroundColorAttributeName value:blueColor range:rangeValue.rangeValue]; } /* symbols */ NSArray *symbolRanges = [self rangesOfCharactersInSet:NSCharacterSet.symbolCharacterSet]; for(NSValue *rangeValue in symbolRanges) { - [string addAttribute:NSForegroundColorAttributeName value:NSColor.blueColor range:rangeValue.rangeValue]; + [string addAttribute:NSForegroundColorAttributeName value:greenColor range:rangeValue.rangeValue]; } /* punktuation */ NSArray *punctiationRanges = [self rangesOfCharactersInSet:NSCharacterSet.punctuationCharacterSet]; for(NSValue *rangeValue in punctiationRanges) { - [string addAttribute:NSForegroundColorAttributeName value:NSColor.greenColor range:rangeValue.rangeValue]; + [string addAttribute:NSForegroundColorAttributeName value:orangeColor range:rangeValue.rangeValue]; } }