From 62e36565b8d3829fe73fbc2233fd22aa50e15e54 Mon Sep 17 00:00:00 2001 From: QQLS <702166055@qq.com> Date: Sat, 6 May 2017 15:26:17 +0800 Subject: [PATCH 1/2] Add night/multiple themes for UITabBarItem. --- Example/Example.xcodeproj/project.pbxproj | 12 ++++ Example/Example/AppDelegate.m | 28 ++++++-- .../AppIcon.appiconset/Contents.json | 10 +++ .../Contents.json | 21 ++++++ .../tabBar_association_normal@2x.png | Bin 0 -> 1570 bytes .../Contents.json | 21 ++++++ .../tabBar_association_selected@2x.png | Bin 0 -> 1906 bytes .../Contents.json | 21 ++++++ .../tabBar_profile_normal@2x.png | Bin 0 -> 1810 bytes .../Contents.json | 21 ++++++ .../tabBar_profile_selected@2x.png | Bin 0 -> 1762 bytes Example/Example/DKAttribute.h | 19 +++++ Example/Example/DKAttribute.m | 41 +++++++++++ Example/Example/UITabBarItem+Night.h | 19 +++++ Example/Example/UITabBarItem+Night.m | 66 ++++++++++++++++++ 15 files changed, 275 insertions(+), 4 deletions(-) create mode 100644 Example/Example/Assets.xcassets/tabBar_association_normal.imageset/Contents.json create mode 100644 Example/Example/Assets.xcassets/tabBar_association_normal.imageset/tabBar_association_normal@2x.png create mode 100644 Example/Example/Assets.xcassets/tabBar_association_selected.imageset/Contents.json create mode 100644 Example/Example/Assets.xcassets/tabBar_association_selected.imageset/tabBar_association_selected@2x.png create mode 100644 Example/Example/Assets.xcassets/tabBar_profile_normal.imageset/Contents.json create mode 100644 Example/Example/Assets.xcassets/tabBar_profile_normal.imageset/tabBar_profile_normal@2x.png create mode 100644 Example/Example/Assets.xcassets/tabBar_profile_selected.imageset/Contents.json create mode 100644 Example/Example/Assets.xcassets/tabBar_profile_selected.imageset/tabBar_profile_selected@2x.png create mode 100644 Example/Example/DKAttribute.h create mode 100644 Example/Example/DKAttribute.m create mode 100644 Example/Example/UITabBarItem+Night.h create mode 100644 Example/Example/UITabBarItem+Night.m diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index d2cf20ac..a90d9e79 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 37A0AF191EBDAC5700CE059B /* DKAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 37A0AF181EBDAC5700CE059B /* DKAttribute.m */; }; + 37A0AF1C1EBDAC6300CE059B /* UITabBarItem+Night.m in Sources */ = {isa = PBXBuildFile; fileRef = 37A0AF1B1EBDAC6300CE059B /* UITabBarItem+Night.m */; }; 7261ADF91CB9FB2D007E283C /* PresentingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7261ADF21CB9FB2D007E283C /* PresentingViewController.m */; }; 7261ADFA1CB9FB2D007E283C /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7261ADF41CB9FB2D007E283C /* RootViewController.m */; }; 7261ADFB1CB9FB2D007E283C /* SuccViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7261ADF61CB9FB2D007E283C /* SuccViewController.m */; }; @@ -22,6 +24,10 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 37A0AF171EBDAC5700CE059B /* DKAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DKAttribute.h; sourceTree = ""; }; + 37A0AF181EBDAC5700CE059B /* DKAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DKAttribute.m; sourceTree = ""; }; + 37A0AF1A1EBDAC6300CE059B /* UITabBarItem+Night.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITabBarItem+Night.h"; sourceTree = ""; }; + 37A0AF1B1EBDAC6300CE059B /* UITabBarItem+Night.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITabBarItem+Night.m"; sourceTree = ""; }; 7261ADF11CB9FB2D007E283C /* PresentingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PresentingViewController.h; sourceTree = ""; }; 7261ADF21CB9FB2D007E283C /* PresentingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PresentingViewController.m; sourceTree = ""; }; 7261ADF31CB9FB2D007E283C /* RootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = ""; }; @@ -92,6 +98,10 @@ 729324041CB9FAF1009E544E /* Assets.xcassets */, 729324061CB9FAF1009E544E /* LaunchScreen.storyboard */, 729324091CB9FAF1009E544E /* Info.plist */, + 37A0AF171EBDAC5700CE059B /* DKAttribute.h */, + 37A0AF181EBDAC5700CE059B /* DKAttribute.m */, + 37A0AF1A1EBDAC6300CE059B /* UITabBarItem+Night.h */, + 37A0AF1B1EBDAC6300CE059B /* UITabBarItem+Night.m */, 729323F81CB9FAF1009E544E /* Supporting Files */, ); path = Example; @@ -180,6 +190,8 @@ 7261ADFC1CB9FB2D007E283C /* TableViewCell.m in Sources */, 729324001CB9FAF1009E544E /* ViewController.m in Sources */, 729323FD1CB9FAF1009E544E /* AppDelegate.m in Sources */, + 37A0AF1C1EBDAC6300CE059B /* UITabBarItem+Night.m in Sources */, + 37A0AF191EBDAC5700CE059B /* DKAttribute.m in Sources */, 729323FA1CB9FAF1009E544E /* main.m in Sources */, 7261ADF91CB9FB2D007E283C /* PresentingViewController.m in Sources */, 7261ADFB1CB9FB2D007E283C /* SuccViewController.m in Sources */, diff --git a/Example/Example/AppDelegate.m b/Example/Example/AppDelegate.m index 534bd513..fa4bf0be 100644 --- a/Example/Example/AppDelegate.m +++ b/Example/Example/AppDelegate.m @@ -9,6 +9,9 @@ #import "AppDelegate.h" #import "RootViewController.h" #import "SuccViewController.h" +#import "ViewController.h" + +#import "UITabBarItem+Night.h" @interface AppDelegate () @@ -18,13 +21,30 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + RootViewController *vc1 = [[RootViewController alloc] init]; + vc1.tabBarItem.title = @"Root"; + vc1.tabBarItem.image = [UIImage imageNamed:@"tabBar_association_normal"]; + vc1.tabBarItem.image = [UIImage imageNamed:@"tabBar_association_selected"]; + [vc1.tabBarItem dk_setTitleAttributePicker:DKAttributePickerWithAttributes(@{NSForegroundColorAttributeName: [UIColor blackColor]}, @{NSForegroundColorAttributeName: [UIColor orangeColor]}, @{NSForegroundColorAttributeName: [UIColor grayColor]}) forState:(UIControlStateNormal)]; + [vc1.tabBarItem dk_setTitleAttributePicker:DKAttributePickerWithAttributes(@{NSForegroundColorAttributeName: [UIColor redColor]}, @{NSForegroundColorAttributeName: [UIColor blueColor]}, @{NSForegroundColorAttributeName: [UIColor greenColor]}) forState:(UIControlStateSelected)]; + UINavigationController *navigation1 = [[UINavigationController alloc] initWithRootViewController:vc1]; + + ViewController *vc2 = [[ViewController alloc] init]; + vc2.tabBarItem.title = @"My"; + vc2.tabBarItem.image = [UIImage imageNamed:@"tabBar_profile_normal"]; + vc2.tabBarItem.image = [UIImage imageNamed:@"tabBar_profile_selected"]; + [vc2.tabBarItem dk_setTitleAttributePicker:DKAttributePickerWithAttributes(@{NSForegroundColorAttributeName: [UIColor blackColor]}, @{NSForegroundColorAttributeName: [UIColor orangeColor]}, @{NSForegroundColorAttributeName: [UIColor grayColor]}) forState:(UIControlStateNormal)]; + [vc2.tabBarItem dk_setTitleAttributePicker:DKAttributePickerWithAttributes(@{NSForegroundColorAttributeName: [UIColor redColor]}, @{NSForegroundColorAttributeName: [UIColor blueColor]}, @{NSForegroundColorAttributeName: [UIColor greenColor]}) forState:(UIControlStateSelected)]; + UINavigationController *navigation2 = [[UINavigationController alloc] initWithRootViewController:vc2]; + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; + UITabBarController *tabController = [[UITabBarController alloc] init]; + tabController.viewControllers = @[navigation1, navigation2]; + self.window.rootViewController = tabController; [self.window makeKeyAndVisible]; - UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]]; - self.window.rootViewController = navigation; - UISearchBar *searchBar = [[UISearchBar alloc] init]; + return YES; } diff --git a/Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json index 118c98f7..b8236c65 100644 --- a/Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", diff --git a/Example/Example/Assets.xcassets/tabBar_association_normal.imageset/Contents.json b/Example/Example/Assets.xcassets/tabBar_association_normal.imageset/Contents.json new file mode 100644 index 00000000..5f93eb47 --- /dev/null +++ b/Example/Example/Assets.xcassets/tabBar_association_normal.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "tabBar_association_normal@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/Example/Assets.xcassets/tabBar_association_normal.imageset/tabBar_association_normal@2x.png b/Example/Example/Assets.xcassets/tabBar_association_normal.imageset/tabBar_association_normal@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..a4eda3afc6291cafce98b1ef5f9ff08831671da7 GIT binary patch literal 1570 zcmV+-2Hp9IP)00004XF*Lt006O% z3;baP0000WV@Og>004R>004l5008;`004mK004C`008P>0026e000+ooVrmw00002 zVoOIv0063uBQgL01wBbbK~z}7t(aMCRz(!Yf9?0RP*ey@%PM6liyEwCs0c_95zyem zVn`H%k$@-7O}+K#W*H0fIRBh#A5j=-h0uKm65VD3z-u#j+H9U zJBo=sP5}U?SWcB}zYfGEnELutW*Sq{w);7A z-py)lxrpN4bfcJ8P?KwX9_p9w-Nh6se`J zDw9p0_{77#=K`w(lT1@(w){d`kwZMI$~;$uV~kCL%O315I@YFu;~J79m&qU|mrJT7 z>N%@Q$5g+IIM2__vKA`(CNnJnyA^egN8HMRptqtUF^T;h z?8bP+zAewP_EgkFJn<*sP4S5RhTB_Kzq_JVyRi5@6EkCfHukWrZ56d5p8Tb#bv$B! zJGx$E@aI*xz~H)Xw(*%E89{R#-+UIuVmt z8d;>uSnv6#70`o>V&EZF>f&Y$%N4CN2>_|rDF+i{U?|HS1Flqi~(}wk`yd(9lm`GyNF|gr}1CS#uQ_Bw~HA(((Xu!x`&Da!$Xy?&do(a;LJTsrB z6xwPE!?eJ+p}1n8j3OY1D!Z#+vx43tA>|UN7filc!37qk5KNH4awfG41)0e`{Go=; zz%UON_#0|ccbYm%q$bpD{V3-V#{f;0O45jIrl(2rASJAqBS0;;g=3Pm^U%Q{ttsIX z202=tB5Q~ta+!6k^Ax|{)B-TeoFKos+r=}R)GG&oznLl<E#Im@jO=PAu40U5 z+~S?&7tr5683XV;(`8GG=-RWNF46uZ+m(2v_iP)Yt!Ad|rlm4F9W7*ArEIelTDXjx zW$;zdI?u!bV%ckzH2;fVExjPGNZdndSXQTZCqZ5|?=qV1dOGrnW1Re>M5;|6#*n0z zVqRDCS}JHm7xuXBKqj)*gCEILS5IxVxPv=AsJADsv+iLB{9gro!FVk+>TFqV74r zwEqtUkzzT-1DO{9001R)MObuXVRU6WV{&C-bY%cCFflhRFf=VPHdHY+Ix#jnFfl7I zI65#eUKUID0000bbVXQnWMOn=I&E)cX=Zr07*qoM6N<$g7}Qf@Bjb+ literal 0 HcmV?d00001 diff --git a/Example/Example/Assets.xcassets/tabBar_association_selected.imageset/Contents.json b/Example/Example/Assets.xcassets/tabBar_association_selected.imageset/Contents.json new file mode 100644 index 00000000..e22cd2db --- /dev/null +++ b/Example/Example/Assets.xcassets/tabBar_association_selected.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "tabBar_association_selected@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/Example/Assets.xcassets/tabBar_association_selected.imageset/tabBar_association_selected@2x.png b/Example/Example/Assets.xcassets/tabBar_association_selected.imageset/tabBar_association_selected@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..39be7daecbd0d1e04df0226dc3edb756c7e54c5e GIT binary patch literal 1906 zcmV-&2aWiNP)004R>004l5008;`004mK004C`008P>0026e000+ooVrmw00006 zVoOIv00000008+zyMF)x28l^TK~!ko#hPiXokJMMfA{uw^wySE7wZ(Q8cUT>yNInw zEmh(J4I!%Z1BopfVqaP$M9|g}gjiy0d?=BAs5FX-s(lDeJF!)Z*qLhi@XnRfxzC(; z-gDl2`~Pyz`+uI9GygN&Gtayo)CjB9!N5e|G+=k28(0f00&X_We^BS|wSul1M2-Y* z1g0lkh5=^)^MtZT0+WHWfDsL*AAoy+g~s`}>J;43hR{yn7GP#(k>iZ>3$0c=12+Rx zEBxH^z)a)(7n?+|)oOd-LttoyVpD*#fz#V)?~}lE>BjPn~Lqt$9x;BMd)!Mwz3wXbph{VD>od)R8V z9Ys&X*iBkYtX4CC`xDhoH_ks;;kPFMOB3dy#`&Le>*}oV=bRyMhb6@B&_wK>Rm1`q z=idRgOPC+7Qdbqh@vvHAoL`dgotJ;29a03&*qXh1SI>a{MJ%Jlpr{K*pIe=XR?yH&wOQ)_a z>J%*bbtinaz-^#jNQ>W=bqbamJS5>O4Xw71p%J7JQ)>_ZEpR&~e76#~)bMW=KMLHS zIt5F|v3(N00|YMX->-l_1#Vz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)MObuXVRU6WV{&C- zbY%cCFflhRFf=VPHdHY+Ix#gmGdC+RI65#eSboAS0000bbVXQnWMOn=I&E)cX=Zr< sGB7bWEig1KGB#8(H99dhIx{ybFgQ9eFexK?kpKVy07*qoM6N<$g3B&`XaE2J literal 0 HcmV?d00001 diff --git a/Example/Example/Assets.xcassets/tabBar_profile_normal.imageset/Contents.json b/Example/Example/Assets.xcassets/tabBar_profile_normal.imageset/Contents.json new file mode 100644 index 00000000..e24136a1 --- /dev/null +++ b/Example/Example/Assets.xcassets/tabBar_profile_normal.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "tabBar_profile_normal@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/Example/Assets.xcassets/tabBar_profile_normal.imageset/tabBar_profile_normal@2x.png b/Example/Example/Assets.xcassets/tabBar_profile_normal.imageset/tabBar_profile_normal@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..41f4e386a62be370b3d18f8a14eb830758f8c25b GIT binary patch literal 1810 zcmV+t2krQYP)004R>004l5008;`004mK004C`008P>0026e000+ooVrmw00002 zVoOIv0063uBQgL01}#ZMK~z}7<(X@26-5+)zt)09Eu}Pyl$eNAtdIh7peicyL1{Hw zQ2{N~M2u0;L@&D5i(rB4sH4_v zu!OhyNKY0fDf-Kb^~w*^#RGhVkH7g%5x&$((dkLdc0-np8&jC9q9nCE-uUa<6Ll^ddo zY5H|0sOveHm$|~-Zngf}1+WZYr>l(7b=g8)|7%$5Dy8~exCIkKoTv?)pvVN4nPPGHS*N&Ka%ntySkMM0 znqs4bSSg==$%9M*V1~YS;#h$8Z%R6-2KsTJ{j;P#_-leZbJ_hTLRxa}R%*O9R-Jf*zD06L!?9#_! zpNhhQu5l^RFos9Zm`{T&3!V(Xay=B;Wr8a`gHM*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ye z3Ej1`431OfXU#4%#65OD`P3Y%$jadK=yUK!CAkUllAUl}|L|e)W2XERskeTM8~Ncm ziu2efkJ0Imj-xZWTI){_@v*ep$`b}Bzg%y;OS-wlNR{0o zhY{$u69jsGM}2Y0r;-vCnUI18lZAoFxfTC|ytiB?bAYuM0{(HfN=tM0GyijqV^)&R ztSf6T806ff0D4D=10!8t^^ncgVL#@R%qmFVC2;#BD;uvfyU*J50y#Stz(0`2tI@>h z2FRxKx^N2H?dA8A(5|`VCClp?H;QS0CqyR;B{^#%1Y3ZbPUC0Rzj$g$cGE%vp4VX>)K1(CJ4%G$MUOI_VBcnO+47w)r2D3P+M-( zPSuz0DHH$XV*5^ib+dc|?Utt=EJKuWthu0md`=%itl*Q<-s4e2Hu2oeC3)Af z>Ku73;Z&O9;{DP+!wWzD@SL~QGkP*in&`b)1;=WMUBALnv*q)R2K}FSZglG_Ox-kC zK%U6z zmlcB4mgnB6H55vi3BzKiikQ%runlKnPX7_%D}1lAi|iK|rg;+6qDW~JdvXdz2EYPi zZexP6GO@r0nOobN+uCC+jWDu`nQ);c{Es2wQdBH8 + +typedef NSString DKThemeVersion; + +typedef NSDictionary *(^DKAttributePicker)(DKThemeVersion *themeVersion); + +DKAttributePicker DKAttributePickerWithAttributes(NSDictionary *normal, ...); + +@interface DKAttribute : NSObject + +@end diff --git a/Example/Example/DKAttribute.m b/Example/Example/DKAttribute.m new file mode 100644 index 00000000..105320ca --- /dev/null +++ b/Example/Example/DKAttribute.m @@ -0,0 +1,41 @@ +// +// DKAttribute.m +// ESports +// +// Created by 时彬强 on 2017/5/5. +// Copyright © 2017年 QQLS. All rights reserved. +// + +#import "DKAttribute.h" + +#import +//#import "DKNightVersionManager.h" +//#import "DKColorTable.h" + +@implementation DKAttribute + +DKAttributePicker DKAttributePickerWithAttributes(NSDictionary *normal, ...) { + + NSArray *themes = [DKColorTable sharedColorTable].themes; + NSMutableArray *attributes = [[NSMutableArray alloc] initWithCapacity:themes.count]; + [attributes addObject:normal]; + NSUInteger num_args = themes.count - 1; + va_list colors_list; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wvarargs" + va_start(colors_list, num_args); +#pragma clang diagnostic pop + + for (NSUInteger i = 0; i < num_args; i++) { + NSDictionary *attribute = va_arg(colors_list, NSDictionary *); + [attributes addObject:attribute]; + } + va_end(colors_list); + + return ^(DKThemeVersion *themeVersion) { + NSUInteger index = [themes indexOfObject:themeVersion]; + return attributes[index]; + }; +} + +@end diff --git a/Example/Example/UITabBarItem+Night.h b/Example/Example/UITabBarItem+Night.h new file mode 100644 index 00000000..5261d1f9 --- /dev/null +++ b/Example/Example/UITabBarItem+Night.h @@ -0,0 +1,19 @@ +// +// UITabBarItem+Night.h +// ESports +// +// Created by 时彬强 on 2017/5/5. +// Copyright © 2017年 QQLS. All rights reserved. +// + +#import + +#import "DKAttribute.h" +#import +//#import "NSObject+Night.h" + +@interface UITabBarItem (Night) + +- (void)dk_setTitleAttributePicker:(DKAttributePicker)picker forState:(UIControlState)state; + +@end diff --git a/Example/Example/UITabBarItem+Night.m b/Example/Example/UITabBarItem+Night.m new file mode 100644 index 00000000..364c11a1 --- /dev/null +++ b/Example/Example/UITabBarItem+Night.m @@ -0,0 +1,66 @@ +// +// UITabBarItem+Night.m +// ESports +// +// Created by 时彬强 on 2017/5/5. +// Copyright © 2017年 QQLS. All rights reserved. +// + +#import "UITabBarItem+Night.h" + +@interface UITabBarItem () + +@property (nonatomic, strong) NSMutableDictionary *pickers; + +@end + +@implementation UITabBarItem (Night) + +- (void)dk_setTitleAttributePicker:(DKAttributePicker)picker forState:(UIControlState)state { + + [self setTitleTextAttributes:picker(self.dk_manager.themeVersion) forState:state]; + NSString *key = [NSString stringWithFormat:@"%@", @(state)]; + NSMutableDictionary *dictionary = [self.pickers valueForKey:key]; + if (!dictionary) { + dictionary = [[NSMutableDictionary alloc] init]; + } + [dictionary setValue:[picker copy] forKey:NSStringFromSelector(@selector(setTitleTextAttributes:forState:))]; + [self.pickers setValue:dictionary forKey:key]; +} + +- (void)night_updateColor { + + [self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { + if ([obj isKindOfClass:[NSDictionary class]]) { + NSDictionary *dictionary = (NSDictionary *)obj; + [dictionary enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull selector, DKAttributePicker _Nonnull picker, BOOL * _Nonnull stop) { + UIControlState state = [key integerValue]; + if ([selector isEqualToString:NSStringFromSelector(@selector(setTitleTextAttributes:forState:))]) { + NSDictionary *attribute = picker(self.dk_manager.themeVersion); + [self setTitleTextAttributes:attribute forState:state]; + } +// [UIView animateWithDuration:DKNightVersionAnimationDuration +// animations:^{ +// if ([selector isEqualToString:NSStringFromSelector(@selector(setTitleTextAttributes:forState:))]) { +// NSDictionary *attribute = picker(self.dk_manager.themeVersion); +// [self setTitleTextAttributes:attribute forState:state]; +// } +// }]; + }]; + } else { + SEL sel = NSSelectorFromString(key); + DKAttributePicker picker = (DKAttributePicker)obj; + NSDictionary *attribute = picker(self.dk_manager.themeVersion); + [UIView animateWithDuration:DKNightVersionAnimationDuration + animations:^{ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + [self performSelector:sel withObject:attribute]; +#pragma clang diagnostic pop + }]; + + } + }]; +} + +@end From 3e89ffc3b0b3a78cf999a0d644013076ba2328c0 Mon Sep 17 00:00:00 2001 From: QQLS <702166055@qq.com> Date: Wed, 10 May 2017 12:30:43 +0800 Subject: [PATCH 2/2] Add method of "setImage:" and "setSelectedImage:" to "UITabBarItem" for implementing UITabBarItem's image night/multiple themes. --- Example/Example/AppDelegate.m | 8 +++--- Example/Example/UITabBarItem+Night.h | 1 + Example/Example/UITabBarItem+Night.m | 41 ++++++++++++++++++++++------ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Example/Example/AppDelegate.m b/Example/Example/AppDelegate.m index fa4bf0be..1af7e023 100644 --- a/Example/Example/AppDelegate.m +++ b/Example/Example/AppDelegate.m @@ -24,16 +24,16 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( RootViewController *vc1 = [[RootViewController alloc] init]; vc1.tabBarItem.title = @"Root"; - vc1.tabBarItem.image = [UIImage imageNamed:@"tabBar_association_normal"]; - vc1.tabBarItem.image = [UIImage imageNamed:@"tabBar_association_selected"]; + [vc1.tabBarItem dk_setImage:DKImagePickerWithNames(@"tabBar_association_normal", @"tabBar_profile_normal") forState:(UIControlStateNormal)]; + [vc1.tabBarItem dk_setImage:DKImagePickerWithNames(@"tabBar_association_selected", @"tabBar_profile_selected") forState:(UIControlStateSelected)]; [vc1.tabBarItem dk_setTitleAttributePicker:DKAttributePickerWithAttributes(@{NSForegroundColorAttributeName: [UIColor blackColor]}, @{NSForegroundColorAttributeName: [UIColor orangeColor]}, @{NSForegroundColorAttributeName: [UIColor grayColor]}) forState:(UIControlStateNormal)]; [vc1.tabBarItem dk_setTitleAttributePicker:DKAttributePickerWithAttributes(@{NSForegroundColorAttributeName: [UIColor redColor]}, @{NSForegroundColorAttributeName: [UIColor blueColor]}, @{NSForegroundColorAttributeName: [UIColor greenColor]}) forState:(UIControlStateSelected)]; UINavigationController *navigation1 = [[UINavigationController alloc] initWithRootViewController:vc1]; ViewController *vc2 = [[ViewController alloc] init]; vc2.tabBarItem.title = @"My"; - vc2.tabBarItem.image = [UIImage imageNamed:@"tabBar_profile_normal"]; - vc2.tabBarItem.image = [UIImage imageNamed:@"tabBar_profile_selected"]; + [vc2.tabBarItem dk_setImage:DKImagePickerWithNames(@"tabBar_profile_normal", @"tabBar_association_normal") forState:(UIControlStateNormal)]; + [vc2.tabBarItem dk_setImage:DKImagePickerWithNames(@"tabBar_profile_selected", @"tabBar_association_selected") forState:(UIControlStateSelected)]; [vc2.tabBarItem dk_setTitleAttributePicker:DKAttributePickerWithAttributes(@{NSForegroundColorAttributeName: [UIColor blackColor]}, @{NSForegroundColorAttributeName: [UIColor orangeColor]}, @{NSForegroundColorAttributeName: [UIColor grayColor]}) forState:(UIControlStateNormal)]; [vc2.tabBarItem dk_setTitleAttributePicker:DKAttributePickerWithAttributes(@{NSForegroundColorAttributeName: [UIColor redColor]}, @{NSForegroundColorAttributeName: [UIColor blueColor]}, @{NSForegroundColorAttributeName: [UIColor greenColor]}) forState:(UIControlStateSelected)]; UINavigationController *navigation2 = [[UINavigationController alloc] initWithRootViewController:vc2]; diff --git a/Example/Example/UITabBarItem+Night.h b/Example/Example/UITabBarItem+Night.h index 5261d1f9..a044c438 100644 --- a/Example/Example/UITabBarItem+Night.h +++ b/Example/Example/UITabBarItem+Night.h @@ -15,5 +15,6 @@ @interface UITabBarItem (Night) - (void)dk_setTitleAttributePicker:(DKAttributePicker)picker forState:(UIControlState)state; +- (void)dk_setImage:(DKImagePicker)picker forState:(UIControlState)state; @end diff --git a/Example/Example/UITabBarItem+Night.m b/Example/Example/UITabBarItem+Night.m index 364c11a1..12c64e24 100644 --- a/Example/Example/UITabBarItem+Night.m +++ b/Example/Example/UITabBarItem+Night.m @@ -17,8 +17,8 @@ @interface UITabBarItem () @implementation UITabBarItem (Night) - (void)dk_setTitleAttributePicker:(DKAttributePicker)picker forState:(UIControlState)state { - [self setTitleTextAttributes:picker(self.dk_manager.themeVersion) forState:state]; + NSString *key = [NSString stringWithFormat:@"%@", @(state)]; NSMutableDictionary *dictionary = [self.pickers valueForKey:key]; if (!dictionary) { @@ -28,6 +28,28 @@ - (void)dk_setTitleAttributePicker:(DKAttributePicker)picker forState:(UIControl [self.pickers setValue:dictionary forKey:key]; } +- (void)dk_setImage:(DKImagePicker)picker forState:(UIControlState)state { + + if (UIControlStateNormal == state) { + [self setImage:picker(self.dk_manager.themeVersion)]; + } else if (UIControlStateSelected == state) { + [self setSelectedImage:picker(self.dk_manager.themeVersion)]; + } + + NSString *key = [NSString stringWithFormat:@"%@", @(state)]; + NSMutableDictionary *dictionary = [self.pickers valueForKey:key]; + if (!dictionary) { + dictionary = [[NSMutableDictionary alloc] init]; + } + + if (UIControlStateNormal == state) { + [dictionary setValue:[picker copy] forKey:NSStringFromSelector(@selector(setImage:))]; + } else if (UIControlStateSelected == state) { + [dictionary setValue:[picker copy] forKey:NSStringFromSelector(@selector(setSelectedImage:))]; + } + [self.pickers setValue:dictionary forKey:key]; +} + - (void)night_updateColor { [self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { @@ -38,14 +60,17 @@ - (void)night_updateColor { if ([selector isEqualToString:NSStringFromSelector(@selector(setTitleTextAttributes:forState:))]) { NSDictionary *attribute = picker(self.dk_manager.themeVersion); [self setTitleTextAttributes:attribute forState:state]; + } else if ([selector isEqualToString:NSStringFromSelector(@selector(setImage:))]) { + if (UIControlStateNormal == state) { + UIImage *resultImage = ((DKImagePicker)picker)(self.dk_manager.themeVersion); + [self setImage:resultImage]; + } + } else if ([selector isEqualToString:NSStringFromSelector(@selector(setSelectedImage:))]) { + if (UIControlStateSelected == state) { + UIImage *resultImage = ((DKImagePicker)picker)(self.dk_manager.themeVersion); + [self setSelectedImage:resultImage]; + } } -// [UIView animateWithDuration:DKNightVersionAnimationDuration -// animations:^{ -// if ([selector isEqualToString:NSStringFromSelector(@selector(setTitleTextAttributes:forState:))]) { -// NSDictionary *attribute = picker(self.dk_manager.themeVersion); -// [self setTitleTextAttributes:attribute forState:state]; -// } -// }]; }]; } else { SEL sel = NSSelectorFromString(key);