Skip to content

Commit

Permalink
更新Demo UITabBar和UINavigationBar适配iOS15的设置方式示例
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiang1994 committed May 28, 2022
1 parent c88ce6e commit 7b1e6ba
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 23 deletions.
5 changes: 2 additions & 3 deletions LEEThemeDemo/LEEThemeDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,6 @@
TargetAttributes = {
9B00492F1CC9CE25001AC212 = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = 5KA67R3283;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.Push = {
Expand Down Expand Up @@ -3190,7 +3189,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 5KA67R3283;
DEVELOPMENT_TEAM = MHW5BL2Z4W;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/LEEThemeDemo/YYKitDemo/Vendor",
Expand Down Expand Up @@ -3218,7 +3217,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 5KA67R3283;
DEVELOPMENT_TEAM = MHW5BL2Z4W;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/LEEThemeDemo/YYKitDemo/Vendor",
Expand Down
115 changes: 95 additions & 20 deletions LEEThemeDemo/LEEThemeDemo/TabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,40 @@ - (void)initData{

- (void)configTheme {

self.tabBar.lee_theme
.LeeAddBarTintColor(DAY , LEEColorRGB(255, 255, 255))
.LeeAddBarTintColor(NIGHT , LEEColorRGB(40, 40, 40))
.LeeConfigBarTintColor(@"ident1");
self.tabBar.lee_theme.LeeThemeChangingBlock(^(NSString * _Nonnull tag, UITabBar * _Nonnull item) {

// 适配iOS 15的设置方式
if (@available(iOS 13.0, *)){
UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];

[appearance configureWithOpaqueBackground];

if ([tag isEqualToString:DAY]) {
appearance.backgroundColor = LEEColorRGB(255, 255, 255);

} else if ([tag isEqualToString:NIGHT]) {
appearance.backgroundColor = LEEColorRGB(40, 40, 40);

} else {

appearance.backgroundColor = [LEETheme getValueWithTag:tag Identifier:@"ident1"];
}

item.standardAppearance = appearance;

if (@available(iOS 15.0, *)){
item.scrollEdgeAppearance = appearance;
}

} else {
item.barTintColor = [LEETheme getValueWithTag:tag Identifier:@"ident1"];
}
});

// self.tabBar.lee_theme
// .LeeAddBarTintColor(DAY , LEEColorRGB(255, 255, 255))
// .LeeAddBarTintColor(NIGHT , LEEColorRGB(40, 40, 40))
// .LeeConfigBarTintColor(@"ident1");
}

- (void)initSubControllers{
Expand All @@ -59,25 +89,70 @@ - (void)initSubControllers{

nc = [[UINavigationController alloc] initWithRootViewController:[[NSClassFromString(classArray[i])alloc] init]];

nc.navigationBar.lee_theme
.LeeAddBarTintColor(DAY , LEEColorRGB(255, 255, 255))
.LeeAddBarTintColor(NIGHT , LEEColorRGB(85, 85, 85))
.LeeConfigBarTintColor(@"ident1");

nc.navigationBar.lee_theme
.LeeAddCustomConfig(DAY, ^(UINavigationBar *bar) {

bar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor]};
})
.LeeAddCustomConfig(NIGHT, ^(UINavigationBar *bar) {
// 适配iOS 15的设置方式
nc.navigationBar.lee_theme.LeeThemeChangingBlock(^(NSString * _Nonnull tag, UINavigationBar * _Nonnull item) {

bar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
})
.LeeCustomConfig(@"ident7", ^(UINavigationBar *bar, id value) {

bar.titleTextAttributes = @{NSForegroundColorAttributeName : value};
if (@available(iOS 13.0, *)){
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
[appearance configureWithOpaqueBackground];

if ([tag isEqualToString:DAY]) {
appearance.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor]};

appearance.backgroundColor = LEEColorRGB(255, 255, 255);

} else if ([tag isEqualToString:NIGHT]) {
appearance.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

appearance.backgroundColor = LEEColorRGB(85, 85, 85);

} else {
appearance.titleTextAttributes = @{NSForegroundColorAttributeName : [LEETheme getValueWithTag:tag Identifier:@"ident7"]};

appearance.backgroundColor = [LEETheme getValueWithTag:tag Identifier:@"ident1"];
}

item.standardAppearance = appearance;

if (@available(iOS 15.0, *)){
item.scrollEdgeAppearance = appearance;
}

} else {

if ([tag isEqualToString:DAY]) {
item.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor]};

} else if ([tag isEqualToString:NIGHT]) {
item.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

} else {
item.titleTextAttributes = [LEETheme getValueWithTag:tag Identifier:@"ident7"];
}

item.barTintColor = [LEETheme getValueWithTag:tag Identifier:@"ident1"];
}
});

// nc.navigationBar.lee_theme
// .LeeAddBarTintColor(DAY , LEEColorRGB(255, 255, 255))
// .LeeAddBarTintColor(NIGHT , LEEColorRGB(85, 85, 85))
// .LeeConfigBarTintColor(@"ident1");

// nc.navigationBar.lee_theme
// .LeeAddCustomConfig(DAY, ^(UINavigationBar *bar) {
//
// bar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor]};
// })
// .LeeAddCustomConfig(NIGHT, ^(UINavigationBar *bar) {
//
// bar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
// })
// .LeeCustomConfig(@"ident7", ^(UINavigationBar *bar, id value) {
//
// bar.titleTextAttributes = @{NSForegroundColorAttributeName : value};
// });

nc.tabBarItem.title = nameArray[i];
}

Expand Down

0 comments on commit 7b1e6ba

Please sign in to comment.