From db450d57ad2c13e67be1f5ebb491d36db109a3ee Mon Sep 17 00:00:00 2001 From: chenguilong <598604202@qq.com> Date: Mon, 14 Mar 2022 18:41:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4UIColor=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xplan-ios.xcodeproj/project.pbxproj | 14 --- .../Base/Tool/UIColor/UIColor+Extension.h | 19 ---- .../Base/Tool/UIColor/UIColor+Extension.m | 102 ------------------ .../Friend/XPMineAttentionTableViewCell.m | 21 +++- .../Cell/Friend/XPMineFansTableViewCell.m | 21 +++- .../Room/View/StageView/MicroView/MicroView.m | 21 +++- 6 files changed, 57 insertions(+), 141 deletions(-) delete mode 100644 xplan-ios/Base/Tool/UIColor/UIColor+Extension.h delete mode 100644 xplan-ios/Base/Tool/UIColor/UIColor+Extension.m diff --git a/xplan-ios.xcodeproj/project.pbxproj b/xplan-ios.xcodeproj/project.pbxproj index 2d87ab6f..a4820399 100644 --- a/xplan-ios.xcodeproj/project.pbxproj +++ b/xplan-ios.xcodeproj/project.pbxproj @@ -158,7 +158,6 @@ 9B92A37027981F5B00AD168F /* XPSkillCardEditViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B92A36F27981F5B00AD168F /* XPSkillCardEditViewController.m */; }; 9B9EEF4E27C8755C006B0EB3 /* XPSkillCardResourcePropModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9EEF4D27C8755C006B0EB3 /* XPSkillCardResourcePropModel.m */; }; 9B9EEF5427C8AFEA006B0EB3 /* XPSkillCardRecordPropModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B9EEF5327C8AFEA006B0EB3 /* XPSkillCardRecordPropModel.m */; }; - 9BA41F2527CBB7950043B11F /* UIColor+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BA41F2427CBB7950043B11F /* UIColor+Extension.m */; }; 9BA8A47227C5D590000365A3 /* XPVoiceCardCircleLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BA8A47127C5D590000365A3 /* XPVoiceCardCircleLayer.m */; }; 9BA8A47527C60D9F000365A3 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9BA8A47427C60D9F000365A3 /* AudioToolbox.framework */; }; 9BA8A47727C60DF7000365A3 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9BA8A47627C60DF7000365A3 /* AVFoundation.framework */; }; @@ -850,8 +849,6 @@ 9B9EEF4D27C8755C006B0EB3 /* XPSkillCardResourcePropModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPSkillCardResourcePropModel.m; sourceTree = ""; }; 9B9EEF5227C8AFEA006B0EB3 /* XPSkillCardRecordPropModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPSkillCardRecordPropModel.h; sourceTree = ""; }; 9B9EEF5327C8AFEA006B0EB3 /* XPSkillCardRecordPropModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPSkillCardRecordPropModel.m; sourceTree = ""; }; - 9BA41F2327CBB7950043B11F /* UIColor+Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+Extension.h"; sourceTree = ""; }; - 9BA41F2427CBB7950043B11F /* UIColor+Extension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+Extension.m"; sourceTree = ""; }; 9BA8A47027C5D590000365A3 /* XPVoiceCardCircleLayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPVoiceCardCircleLayer.h; sourceTree = ""; }; 9BA8A47127C5D590000365A3 /* XPVoiceCardCircleLayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPVoiceCardCircleLayer.m; sourceTree = ""; }; 9BA8A47427C60D9F000365A3 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; @@ -2065,7 +2062,6 @@ children = ( 9B33E3C827D85379003B0E62 /* File */, E80CBDE727D0C528001E1EC2 /* Timer */, - 9BA41F2227CBB7500043B11F /* UIColor */, 180116F6279E8C3100F2CBC0 /* Date */, 9B17F71527BD14FF00440843 /* SVGAParserManager */, 9B8585F22788699400D7D5C6 /* KVO */, @@ -2556,15 +2552,6 @@ name = "Recovered References"; sourceTree = ""; }; - 9BA41F2227CBB7500043B11F /* UIColor */ = { - isa = PBXGroup; - children = ( - 9BA41F2327CBB7950043B11F /* UIColor+Extension.h */, - 9BA41F2427CBB7950043B11F /* UIColor+Extension.m */, - ); - path = UIColor; - sourceTree = ""; - }; 9BB549632782F96F0090CD26 /* SubViews */ = { isa = PBXGroup; children = ( @@ -5093,7 +5080,6 @@ E84BF7E0277C869A00EF8877 /* XPRoomOnLineViewController.m in Sources */, 186A534826FC6ED900D67B2C /* TTAlertButtonConfig.m in Sources */, E8ACEFF827C9034C00F66D1A /* XPHomeListEmptyTableViewCell.m in Sources */, - 9BA41F2527CBB7950043B11F /* UIColor+Extension.m in Sources */, E89D60BA271D643A001F8895 /* Api+Room.m in Sources */, E872308926E89BE000B90D4F /* LoginPhoneViewController.m in Sources */, E8C6FFEA2755040B004DC9F0 /* XPHomeSearchNavView.m in Sources */, diff --git a/xplan-ios/Base/Tool/UIColor/UIColor+Extension.h b/xplan-ios/Base/Tool/UIColor/UIColor+Extension.h deleted file mode 100644 index 13a5e1db..00000000 --- a/xplan-ios/Base/Tool/UIColor/UIColor+Extension.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// UIColor+Extension.h -// PlanetStar -// -// Created by Runyalsj on 2020/6/16. -// Copyright © 2020 WUJIE INTERACTIVE. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface UIColor (Extension) -+ (UIColor *) colorWithHexString:(NSString *) hexString; -+ (UIColor *) colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha; -+ (NSString *) hexStringFromColor:(UIColor *)color; -@end - -NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Base/Tool/UIColor/UIColor+Extension.m b/xplan-ios/Base/Tool/UIColor/UIColor+Extension.m deleted file mode 100644 index 5a93177a..00000000 --- a/xplan-ios/Base/Tool/UIColor/UIColor+Extension.m +++ /dev/null @@ -1,102 +0,0 @@ -// -// UIColor+Extension.m -// PlanetStar -// -// Created by Runyalsj on 2020/6/16. -// Copyright © 2020 WUJIE INTERACTIVE. All rights reserved. -// - -#import "UIColor+Extension.h" - -@implementation UIColor (Extension) -+ (UIColor *) colorWithHexString: (NSString *) hexString { - NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @"#" withString: @""] uppercaseString]; - CGFloat alpha, red, blue, green; - switch ([colorString length]) { - case 3: // #RGB - alpha = 1.0f; - red = [self colorComponentFrom: colorString start: 0 length: 1]; - green = [self colorComponentFrom: colorString start: 1 length: 1]; - blue = [self colorComponentFrom: colorString start: 2 length: 1]; - break; - case 4: // #ARGB - alpha = [self colorComponentFrom: colorString start: 0 length: 1]; - red = [self colorComponentFrom: colorString start: 1 length: 1]; - green = [self colorComponentFrom: colorString start: 2 length: 1]; - blue = [self colorComponentFrom: colorString start: 3 length: 1]; - break; - case 6: // #RRGGBB - alpha = 1.0f; - red = [self colorComponentFrom: colorString start: 0 length: 2]; - green = [self colorComponentFrom: colorString start: 2 length: 2]; - blue = [self colorComponentFrom: colorString start: 4 length: 2]; - break; - case 8: // #AARRGGBB - alpha = [self colorComponentFrom: colorString start: 0 length: 2]; - red = [self colorComponentFrom: colorString start: 2 length: 2]; - green = [self colorComponentFrom: colorString start: 4 length: 2]; - blue = [self colorComponentFrom: colorString start: 6 length: 2]; - break; - default: - [NSException raise:@"Invalid color value" format: @"Color value %@ is invalid. It should be a hex value of the form #RBG, #ARGB, #RRGGBB, or #AARRGGBB", hexString]; - break; - } - return [UIColor colorWithRed: red green: green blue: blue alpha: alpha]; -} - -+ (UIColor *) colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha { - if (hexString.length == 0) return [UIColor blackColor]; - NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @"#" withString: @""] uppercaseString]; - CGFloat red, blue, green; - switch ([colorString length]) { - case 3: // #RGB - red = [self colorComponentFrom: colorString start: 0 length: 1]; - green = [self colorComponentFrom: colorString start: 1 length: 1]; - blue = [self colorComponentFrom: colorString start: 2 length: 1]; - break; - case 4: // #ARGB - alpha = [self colorComponentFrom: colorString start: 0 length: 1]; - red = [self colorComponentFrom: colorString start: 1 length: 1]; - green = [self colorComponentFrom: colorString start: 2 length: 1]; - blue = [self colorComponentFrom: colorString start: 3 length: 1]; - break; - case 6: // #RRGGBB - red = [self colorComponentFrom: colorString start: 0 length: 2]; - green = [self colorComponentFrom: colorString start: 2 length: 2]; - blue = [self colorComponentFrom: colorString start: 4 length: 2]; - break; - case 8: // #AARRGGBB - alpha = [self colorComponentFrom: colorString start: 0 length: 2]; - red = [self colorComponentFrom: colorString start: 2 length: 2]; - green = [self colorComponentFrom: colorString start: 4 length: 2]; - blue = [self colorComponentFrom: colorString start: 6 length: 2]; - break; - default: - [NSException raise:@"Invalid color value" format: @"Color value %@ is invalid. It should be a hex value of the form #RBG, #ARGB, #RRGGBB, or #AARRGGBB", hexString]; - break; - } - return [UIColor colorWithRed: red green: green blue: blue alpha: alpha]; -} - - -+ (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start length: (NSUInteger) length { - NSString *substring = [string substringWithRange: NSMakeRange(start, length)]; - NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat: @"%@%@", substring, substring]; - unsigned hexComponent; - [[NSScanner scannerWithString: fullHex] scanHexInt: &hexComponent]; - return hexComponent / 255.0; -} - -+ (NSString *)hexStringFromColor:(UIColor *)color { - const CGFloat *components = CGColorGetComponents(color.CGColor); - - CGFloat r = components[0]; - CGFloat g = components[1]; - CGFloat b = components[2]; - - return [NSString stringWithFormat:@"#%02lX%02lX%02lX", - lroundf(r * 255), - lroundf(g * 255), - lroundf(b * 255)]; -} -@end diff --git a/xplan-ios/Main/Mine/View/Cell/Friend/XPMineAttentionTableViewCell.m b/xplan-ios/Main/Mine/View/Cell/Friend/XPMineAttentionTableViewCell.m index 5ab8fa0e..26ba6425 100644 --- a/xplan-ios/Main/Mine/View/Cell/Friend/XPMineAttentionTableViewCell.m +++ b/xplan-ios/Main/Mine/View/Cell/Friend/XPMineAttentionTableViewCell.m @@ -12,7 +12,6 @@ #import "NetImageView.h" #import "ThemeColor.h" #import "UIImage+Utils.h" -#import "UIColor+Extension.h" ///Model #import "FansInfoModel.h" @@ -165,13 +164,31 @@ }]; } if (fansInfo.userVipInfoVO && fansInfo.userVipInfoVO.friendNickColour) { - self.nickLabel.textColor = [UIColor colorWithHexString:fansInfo.userVipInfoVO.friendNickColour]; + self.nickLabel.textColor = [self colorWithHexString:fansInfo.userVipInfoVO.friendNickColour]; } else { self.nickLabel.textColor = [ThemeColor mainTextColor]; } } } +- (UIColor *)colorWithHexString: (NSString *) hexString { + NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @"#" withString: @""] uppercaseString]; + CGFloat alpha, red, blue, green; + alpha = 1.0f; + red = [self colorComponentFrom: colorString start: 0 length: 2]; + green = [self colorComponentFrom: colorString start: 2 length: 2]; + blue = [self colorComponentFrom: colorString start: 4 length: 2]; + return [UIColor colorWithRed: red green: green blue: blue alpha: alpha]; +} + +- (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start length: (NSUInteger) length { + NSString *substring = [string substringWithRange: NSMakeRange(start, length)]; + NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat: @"%@%@", substring, substring]; + unsigned hexComponent; + [[NSScanner scannerWithString: fullHex] scanHexInt: &hexComponent]; + return hexComponent / 255.0; +} + - (NetImageView *)avatarImageView { if (!_avatarImageView) { NetImageConfig * config = [[NetImageConfig alloc]init]; diff --git a/xplan-ios/Main/Mine/View/Cell/Friend/XPMineFansTableViewCell.m b/xplan-ios/Main/Mine/View/Cell/Friend/XPMineFansTableViewCell.m index 4e76dbfc..9d2908f9 100644 --- a/xplan-ios/Main/Mine/View/Cell/Friend/XPMineFansTableViewCell.m +++ b/xplan-ios/Main/Mine/View/Cell/Friend/XPMineFansTableViewCell.m @@ -13,7 +13,6 @@ #import "NetImageView.h" #import "ThemeColor.h" #import "UIImage+Utils.h" -#import "UIColor+Extension.h" ///Model #import "FansInfoModel.h" @@ -170,13 +169,31 @@ } if (fansInfo.userVipInfoVO && fansInfo.userVipInfoVO.friendNickColour) { - self.nickLabel.textColor = [UIColor colorWithHexString:fansInfo.userVipInfoVO.friendNickColour]; + self.nickLabel.textColor = [self colorWithHexString:fansInfo.userVipInfoVO.friendNickColour]; } else { self.nickLabel.textColor = [ThemeColor mainTextColor]; } } } +- (UIColor *)colorWithHexString: (NSString *) hexString { + NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @"#" withString: @""] uppercaseString]; + CGFloat alpha, red, blue, green; + alpha = 1.0f; + red = [self colorComponentFrom: colorString start: 0 length: 2]; + green = [self colorComponentFrom: colorString start: 2 length: 2]; + blue = [self colorComponentFrom: colorString start: 4 length: 2]; + return [UIColor colorWithRed: red green: green blue: blue alpha: alpha]; +} + +- (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start length: (NSUInteger) length { + NSString *substring = [string substringWithRange: NSMakeRange(start, length)]; + NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat: @"%@%@", substring, substring]; + unsigned hexComponent; + [[NSScanner scannerWithString: fullHex] scanHexInt: &hexComponent]; + return hexComponent / 255.0; +} + - (NetImageView *)avatarImageView { if (!_avatarImageView) { NetImageConfig * config = [[NetImageConfig alloc]init]; diff --git a/xplan-ios/Main/Room/View/StageView/MicroView/MicroView.m b/xplan-ios/Main/Room/View/StageView/MicroView/MicroView.m index 5f320079..90aa0ef5 100644 --- a/xplan-ios/Main/Room/View/StageView/MicroView/MicroView.m +++ b/xplan-ios/Main/Room/View/StageView/MicroView/MicroView.m @@ -9,7 +9,6 @@ ///Third #import #import -#import "UIColor+Extension.h" ///View #import "MicroWaveView.h" #import "NetImageView.h" @@ -364,7 +363,7 @@ } self.nickLabel.text = nickStr.length > 0 ? nickStr : @""; if (userInfo.micNickColor.length) { - self.nickLabel.textColor = [UIColor colorWithHexString:userInfo.micNickColor]; + self.nickLabel.textColor = [self colorWithHexString:userInfo.micNickColor]; } else { self.nickLabel.textColor = [ThemeColor positionNickColor]; } @@ -429,6 +428,24 @@ } } +- (UIColor *)colorWithHexString: (NSString *) hexString { + NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @"#" withString: @""] uppercaseString]; + CGFloat alpha, red, blue, green; + alpha = 1.0f; + red = [self colorComponentFrom: colorString start: 0 length: 2]; + green = [self colorComponentFrom: colorString start: 2 length: 2]; + blue = [self colorComponentFrom: colorString start: 4 length: 2]; + return [UIColor colorWithRed: red green: green blue: blue alpha: alpha]; +} + +- (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start length: (NSUInteger) length { + NSString *substring = [string substringWithRange: NSMakeRange(start, length)]; + NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat: @"%@%@", substring, substring]; + unsigned hexComponent; + [[NSScanner scannerWithString: fullHex] scanHexInt: &hexComponent]; + return hexComponent / 255.0; +} + #pragma mark - Getters And Setters - (NetImageView *)avatarImageView { if (!_avatarImageView) {