The project code is put here, this program is stripped from the actual project, we use any problems encountered or any comments welcome at any time ~

Demo do a little ugly, we have more patience 😅

It’s very simple to use:

Initialization:

[[SDThemeManager sharedInstance] setupThemeNameArray:@[@"SDTheme-White"The @"SDTheme-Black"]].Copy the code

Sdtheme-white and sdtheme-black are the names of the resource theme bundles.

Switch themes:

[[SDThemeManager sharedInstance] changeTheme:@"SDTheme-Black"];
Copy the code

Specific setting skin:

Theme_backgroundColor (); theme_backgroundColor ();

self.view.theme_backgroundColor = @"block_bg";
self.textField.theme_textColor = @"text_h1";
self.image.theme_image = @"icon_face";
Copy the code

Rich text need to replace with SDThemeForegroundColorAttributeName NSForegroundColorAttributeName, such as:

navBar.theme_titleTextAttributes = @{SDThemeForegroundColorAttributeName:@"text_h1"};
Copy the code

Some common attributes can also be set directly in visual views such as XIB, for example:

If direct set properties do not meet the demand, can also listen to inform SDThemeChangedNotification, received notice to do color ICONS switching.

Resource management

Color strings and Images are managed in separate bundles, so start by creating your own theme bundle. Bundle and create colormap. plist and images.xcassets

  • Images: Managed by images.xcassets in the corresponding theme bundle, the Images have the same names for different themes.
  • Color strings: Color strings can be referenced in the Demo file, starting with a large category, such as the DemoBlock, text, and line(Follow their own classification is good, here classification I am raking competitive productsRich way niuniu🤠) if you have a category calledSomeThing, the content under the classification should be named with the corresponding prefixSomeThing_Otherwise, it will not be found.color stringIt is in HEX or AHEX format.

Bundle creation Notes:

Resource bundles do not change the extension or use Settings Bundles directly after creating new folders

Bundle creation is recommended:

file
New
Target
macOS
Bundle

Once it’s created, The Base SDK is set to iOS Build Active Architecture Only is set to “YES” Installation Directory Don’t Code Sign iOS Deployment Target set to the appropriate version Skip Install set to “NO” Strip Debug Symbols During Copy set to “YES” COMBINE_HIDPI_IMAGES set to “NO” and set dependencies

Finally:

Warehouse address: SDTheme, ⭐⭐⭐ If you think this warehouse is helpful to you, please don’t spare your ⭐, thank you for your support! ⭐⭐⭐ if you have any questions in use, please feel free to leave a message, but also please see more advice ~