From 6029a5eb67480c31a241ea0d3c409e027807ae1d Mon Sep 17 00:00:00 2001 From: kai60 Date: Sat, 30 Oct 2021 15:23:22 +0800 Subject: [PATCH] =?UTF-8?q?xcode13=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ifish.xcodeproj/project.pbxproj | 20 +- Ifish/AppDelegate.m | 4 +- .../UIImage+WaterMark.h | 0 .../UIImage+WaterMark.m | 0 .../Category/UIViewController+Navgation.h | 44 ++++ .../Category/UIViewController+Navgation.m | 202 ++++++++++++++++++ .../Utinitys/IfishHttpRequest/IFISHHttpTool.h | 2 +- .../Utinitys/IfishHttpRequest/IFISHHttpTool.m | 7 +- .../IfishHttpRequest/IfishDataUnity.m | 24 +-- .../IfishUtils/UINavigationBar+Background.m | 192 ++++++++++++++++- Ifish/ViewController.m | 4 +- .../maincontroller/RightViewController.m | 2 +- .../IfishADTimerViewController.m | 2 +- .../IfishMianTabViewController.m | 8 +- .../mineControllers/IfishSetViewController.m | 2 +- .../设备/IfishDeviceViewController.m | 4 +- .../leftcontrollers/SetViewController.m | 2 +- 17 files changed, 480 insertions(+), 39 deletions(-) rename Ifish/Utinitys/{EGOCache => Category}/UIImage+WaterMark.h (100%) rename Ifish/Utinitys/{EGOCache => Category}/UIImage+WaterMark.m (100%) create mode 100644 Ifish/Utinitys/Category/UIViewController+Navgation.h create mode 100644 Ifish/Utinitys/Category/UIViewController+Navgation.m diff --git a/Ifish.xcodeproj/project.pbxproj b/Ifish.xcodeproj/project.pbxproj index e655c1f..0e0d8d2 100644 --- a/Ifish.xcodeproj/project.pbxproj +++ b/Ifish.xcodeproj/project.pbxproj @@ -2291,6 +2291,8 @@ C0B2F55D244D5577001079AA /* StoreNameView.h in Headers */ = {isa = PBXBuildFile; fileRef = C0B2F55B244D5577001079AA /* StoreNameView.h */; }; C0B2F55E244D5577001079AA /* StoreNameView.m in Sources */ = {isa = PBXBuildFile; fileRef = C0B2F55C244D5577001079AA /* StoreNameView.m */; }; C0B2F560244D568E001079AA /* StoreNameView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C0B2F55F244D568E001079AA /* StoreNameView.xib */; }; + C0C4CCFF272CDF4A00574BE8 /* UIViewController+Navgation.m in Sources */ = {isa = PBXBuildFile; fileRef = C0C4CCFD272CDF4A00574BE8 /* UIViewController+Navgation.m */; }; + C0C4CD00272CDF4A00574BE8 /* UIViewController+Navgation.h in Headers */ = {isa = PBXBuildFile; fileRef = C0C4CCFE272CDF4A00574BE8 /* UIViewController+Navgation.h */; }; C0D3A1282647ED8E008E6FD6 /* ELPCircleConsoleView.m in Sources */ = {isa = PBXBuildFile; fileRef = C0D3A1262647ED8D008E6FD6 /* ELPCircleConsoleView.m */; }; C0D3A1292647ED8E008E6FD6 /* ELPCircleConsoleView.h in Headers */ = {isa = PBXBuildFile; fileRef = C0D3A1272647ED8D008E6FD6 /* ELPCircleConsoleView.h */; }; C0D3A12C2647ED99008E6FD6 /* UIView+Sizes.h in Headers */ = {isa = PBXBuildFile; fileRef = C0D3A12A2647ED99008E6FD6 /* UIView+Sizes.h */; }; @@ -5761,6 +5763,8 @@ C0B2F55B244D5577001079AA /* StoreNameView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StoreNameView.h; sourceTree = ""; }; C0B2F55C244D5577001079AA /* StoreNameView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = StoreNameView.m; sourceTree = ""; }; C0B2F55F244D568E001079AA /* StoreNameView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StoreNameView.xib; sourceTree = ""; }; + C0C4CCFD272CDF4A00574BE8 /* UIViewController+Navgation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Navgation.m"; sourceTree = ""; }; + C0C4CCFE272CDF4A00574BE8 /* UIViewController+Navgation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Navgation.h"; sourceTree = ""; }; C0D3A1262647ED8D008E6FD6 /* ELPCircleConsoleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ELPCircleConsoleView.m; sourceTree = ""; }; C0D3A1272647ED8D008E6FD6 /* ELPCircleConsoleView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ELPCircleConsoleView.h; sourceTree = ""; }; C0D3A12A2647ED99008E6FD6 /* UIView+Sizes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Sizes.h"; sourceTree = ""; }; @@ -10030,6 +10034,7 @@ 883E791A1D48ACFF0030E075 /* Utinitys */ = { isa = PBXGroup; children = ( + C0C4CCFC272CDEDA00574BE8 /* Category */, C0837A54244FF5500034FEC5 /* EGOCache */, 885BD30E1E260B3C00CDB65A /* shuomingshu.html */, 887495541DAE1B2D00F8F4E2 /* IfishUtils */, @@ -12284,8 +12289,6 @@ C0837A54244FF5500034FEC5 /* EGOCache */ = { isa = PBXGroup; children = ( - C017B1E0245ED2D3003151DF /* UIImage+WaterMark.h */, - C017B1E1245ED2D4003151DF /* UIImage+WaterMark.m */, C0837A55244FF5500034FEC5 /* EGOCache.m */, C0837A56244FF5500034FEC5 /* EGOCache.h */, ); @@ -12312,6 +12315,17 @@ name = petsStoreName; sourceTree = ""; }; + C0C4CCFC272CDEDA00574BE8 /* Category */ = { + isa = PBXGroup; + children = ( + C0C4CCFE272CDF4A00574BE8 /* UIViewController+Navgation.h */, + C0C4CCFD272CDF4A00574BE8 /* UIViewController+Navgation.m */, + C017B1E0245ED2D3003151DF /* UIImage+WaterMark.h */, + C017B1E1245ED2D4003151DF /* UIImage+WaterMark.m */, + ); + path = Category; + sourceTree = ""; + }; C0D3A11B2647EB9F008E6FD6 /* ZLRocker */ = { isa = PBXGroup; children = ( @@ -13159,6 +13173,7 @@ CBB0244123517947002900D5 /* MJExtensionConst.h in Headers */, CBB0243A23517947002900D5 /* NSObject+MJClass.h in Headers */, 3D1C5144221A9EE10096AE43 /* MonitorBootmView.h in Headers */, + C0C4CD00272CDF4A00574BE8 /* UIViewController+Navgation.h in Headers */, 3D1C50D3221A9EE00096AE43 /* UIScrollView+SVInfiniteScrolling.h in Headers */, CBA61655228F9A6C00ED380D /* YYModel.h in Headers */, CB484DFE22B8C8C80075F050 /* cpu.h in Headers */, @@ -14879,6 +14894,7 @@ 3D1C50A4221A9EDF0096AE43 /* ProgressImageView.m in Sources */, CB7D6AA022953BEB0014E5C7 /* YYDiskCache.m in Sources */, 883E793E1D48ACFF0030E075 /* AFHttpTool.m in Sources */, + C0C4CCFF272CDF4A00574BE8 /* UIViewController+Navgation.m in Sources */, 3DD7AB5121E2F2FB0064856A /* mask.c in Sources */, 883E787C1D48A5E50030E075 /* IfishMeViewController.m in Sources */, CBA61683228F9AB100ED380D /* MASConstraintMaker.m in Sources */, diff --git a/Ifish/AppDelegate.m b/Ifish/AppDelegate.m index bd83ebf..5ffdf40 100644 --- a/Ifish/AppDelegate.m +++ b/Ifish/AppDelegate.m @@ -301,7 +301,7 @@ if (kScreenSize.height>480) { UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:logVC]; self.window.rootViewController=nav; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; }else{ @@ -313,7 +313,7 @@ if (kScreenSize.height>480) { UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:registVC]; self.window.rootViewController=nav; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; } } diff --git a/Ifish/Utinitys/EGOCache/UIImage+WaterMark.h b/Ifish/Utinitys/Category/UIImage+WaterMark.h similarity index 100% rename from Ifish/Utinitys/EGOCache/UIImage+WaterMark.h rename to Ifish/Utinitys/Category/UIImage+WaterMark.h diff --git a/Ifish/Utinitys/EGOCache/UIImage+WaterMark.m b/Ifish/Utinitys/Category/UIImage+WaterMark.m similarity index 100% rename from Ifish/Utinitys/EGOCache/UIImage+WaterMark.m rename to Ifish/Utinitys/Category/UIImage+WaterMark.m diff --git a/Ifish/Utinitys/Category/UIViewController+Navgation.h b/Ifish/Utinitys/Category/UIViewController+Navgation.h new file mode 100644 index 0000000..755a649 --- /dev/null +++ b/Ifish/Utinitys/Category/UIViewController+Navgation.h @@ -0,0 +1,44 @@ +// +// UIViewController+Navgation.h +// E-Mobile7 +// +// Created by ldg on 2018/4/13. +// Copyright © 2018年 Weaver. All rights reserved. +// + +#import + + + +@interface UIViewController (Navgation) + + + + + +/** + * 设置导航栏背景颜色 + */ +- (void)setNavbgColorStr:(NSString *)colorStr; + +/** + * 设置导航栏背景图片 + */ +- (void)setNavbgImage:(UIImage *)image; +//获取 +-(UIImage*)getNaveImage; + +- (void)setNavbgColor:(UIColor *)color; + +/** + * 设置导航栏文字颜色 + */ +- (void)setNavTitleColor:(UIColor *)color; +//字体和颜色 + +- (void)setNavTitleTextAttributes:(NSDictionary*)attribute; + +//字体 +- (void)setNavTitleFont:(UIFont *)font; +- (UINavigationBarAppearance *)getNavgationAppearanceWithNavgationController:(UINavigationBar *)bar API_AVAILABLE(ios(13.0)); +@end diff --git a/Ifish/Utinitys/Category/UIViewController+Navgation.m b/Ifish/Utinitys/Category/UIViewController+Navgation.m new file mode 100644 index 0000000..1f616d8 --- /dev/null +++ b/Ifish/Utinitys/Category/UIViewController+Navgation.m @@ -0,0 +1,202 @@ + + +// +// UIViewController+Navgation.m +// E-Mobile7 +// +// Created by ldg on 2018/4/13. +// Copyright © 2018年 Weaver. All rights reserved. +// + +#import "UIViewController+Navgation.h" + + +@implementation UIViewController (Navgation) + + ++ (UIColor *)colorWithHexString:(NSString *)stringToConvert +{ + if ([stringToConvert hasPrefix:@"#"]) + { + stringToConvert = [stringToConvert substringFromIndex:1]; + } + float alpha=1.0; + if (stringToConvert.length>6&&![stringToConvert hasPrefix:@"0x"])//含有透明度 + { + NSString*alphaString=[stringToConvert substringToIndex:2]; + NSScanner *alphaScanner = [NSScanner scannerWithString:alphaString]; + unsigned hex; + + if (![alphaScanner scanHexInt:&hex]) + { + alpha=1.0; + } + else + { + const char *hexChar = [alphaString cStringUsingEncoding:NSUTF8StringEncoding]; + int hexNumber; + sscanf(hexChar, "%x", &hexNumber); + + alpha=hexNumber/255.0; + + } + } + + NSScanner *scanner = [NSScanner scannerWithString:stringToConvert]; + unsigned hexNum; + + if (![scanner scanHexInt:&hexNum]) + { + return [UIColor clearColor]; + } + + return [UIColor \ + colorWithRed:((float)((hexNum & 0xFF0000) >> 16))/255.0 \ + green:((float)((hexNum & 0xFF00) >> 8))/255.0 \ + blue:((float)(hexNum & 0xFF))/255.0 alpha:alpha]; +} ++ (UIImage *)createImageWithColor:(UIColor *)color +{ + CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); + UIGraphicsBeginImageContext(rect.size); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextSetFillColorWithColor(context, [color CGColor]); + CGContextFillRect(context, rect); + UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return theImage; +} + +- (void)setNavbgColorStr:(NSString *)colorStr +{ + + UIImage *image = [self.class createImageWithColor:[self.class colorWithHexString:colorStr]]; + [self setNavbgImage:image]; +} +- (void)setNavbgColor:(UIColor *)color +{ + UIImage *image = [self.class createImageWithColor:color]; + [self setNavbgImage:image]; +} +- (void)setNavbgImage:(UIImage *)image +{ + UINavigationController *nav = nil; + if ([self isKindOfClass:UINavigationController.class]) { + nav = (UINavigationController *)self; + }else{ + nav = self.navigationController; + } + if (image && nav) { + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *apperar = [self getNavgationAppearanceWithNavgationController:nav.navigationBar]; + apperar.backgroundImage = image; + nav.navigationBar.standardAppearance = apperar; + nav.navigationBar.scrollEdgeAppearance = apperar; + }else{ + [nav.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; + } + } +} +-(UIImage*)getNaveImage +{ + UINavigationController *nav = nil; + if ([self isKindOfClass:UINavigationController.class]) { + nav = (UINavigationController *)self; + }else{ + nav = self.navigationController; + } + if (nav) { + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *apperar = [self getNavgationAppearanceWithNavgationController:nav.navigationBar]; + return apperar.backgroundImage; + }else{ + + return [nav.navigationBar + backgroundImageForBarMetrics:UIBarMetricsDefault]; + } + } + return nil; +} + +- (UINavigationBarAppearance *)getNavgationAppearanceWithNavgationController:(UINavigationBar *)bar +API_AVAILABLE(ios(13.0)){ + if (@available(iOS 15.0, *)) { + if (bar.standardAppearance) { + return bar.standardAppearance; + } + + if (bar.scrollEdgeAppearance) { + return bar.scrollEdgeAppearance; + } + + return [[UINavigationBarAppearance alloc] init]; + } + return nil; +} + +- (void)setNavTitleColor:(UIColor *)color +{ + UINavigationController *nav = nil; + if ([self isKindOfClass:UINavigationController.class]) { + nav = (UINavigationController *)self; + }else{ + nav = self.navigationController; + } + if (color && nav) { + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *apperar = [self getNavgationAppearanceWithNavgationController:nav.navigationBar]; + apperar.titleTextAttributes = @{NSForegroundColorAttributeName:color}; + nav.navigationBar.standardAppearance = apperar; + nav.navigationBar.scrollEdgeAppearance = apperar; + }else{ + nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:color}; + } + + } +} + + +- (void)setNavTitleFont:(UIFont *)font +{ + UINavigationController *nav = nil; + if ([self isKindOfClass:UINavigationController.class]) { + nav = (UINavigationController *)self; + }else{ + nav = self.navigationController; + } + if (font && nav) { + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *apperar = [self getNavgationAppearanceWithNavgationController:nav.navigationBar]; + apperar.titleTextAttributes = @{NSFontAttributeName:font}; + nav.navigationBar.standardAppearance = apperar; + nav.navigationBar.scrollEdgeAppearance = apperar; + }else{ + nav.navigationBar.titleTextAttributes = @{NSFontAttributeName:font}; + } + + } +} +- (void)setNavTitleTextAttributes:(NSDictionary*)attribute +{ + UINavigationController *nav = nil; + if ([self isKindOfClass:UINavigationController.class]) { + nav = (UINavigationController *)self; + }else{ + nav = self.navigationController; + } + if (attribute && nav) { + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *apperar = [self getNavgationAppearanceWithNavgationController:nav.navigationBar]; + apperar.titleTextAttributes = attribute; + nav.navigationBar.standardAppearance = apperar; + nav.navigationBar.scrollEdgeAppearance = apperar; + }else{ + nav.navigationBar.titleTextAttributes = attribute; + } + + } +} + + + +@end diff --git a/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.h b/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.h index 9b7e3c9..83c3743 100644 --- a/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.h +++ b/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.h @@ -32,7 +32,7 @@ #import "SonNuoCenterViewController.h" #import "ShopCertifyStausModel.h" #import "CertificationShopModel.h" - +#import "UIViewController+Navgation.h" #import diff --git a/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.m b/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.m index e6ff944..7f59a39 100644 --- a/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.m +++ b/Ifish/Utinitys/IfishHttpRequest/IFISHHttpTool.m @@ -105,7 +105,8 @@ LogInViewController*logvc=[[LogInViewController alloc]init]; UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:logvc]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; + app1.window.rootViewController=nav; [app1.window makeToast:@"验证失败,密码不正确"]; @@ -118,7 +119,7 @@ DisconnectNetController *connectVC =[[DisconnectNetController alloc] init]; UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:connectVC]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; } @@ -128,7 +129,7 @@ DisconnectNetController *connectVC =[[DisconnectNetController alloc] init]; UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:connectVC]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; NSString *errstr = [NSString stringWithFormat:@"%@",err]; BLYLog(BuglyLogLevelWarn, errstr); diff --git a/Ifish/Utinitys/IfishHttpRequest/IfishDataUnity.m b/Ifish/Utinitys/IfishHttpRequest/IfishDataUnity.m index 571b095..2832015 100644 --- a/Ifish/Utinitys/IfishHttpRequest/IfishDataUnity.m +++ b/Ifish/Utinitys/IfishHttpRequest/IfishDataUnity.m @@ -161,7 +161,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:ruSuncenter]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; }else if ([devicemodel.type isEqualToString:DECICE_TYPE_JUNENGCC]){ @@ -175,7 +175,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:SongNuoBDcenter]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; }else if ([devicemodel.type isEqualToString:DECICE_TYPE_RUSUN2A]){ @@ -185,7 +185,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:RunSun84center]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; } else if ([devicemodel.type isEqualToString:DECICE_TYPE_RUIMEI]) { @@ -194,7 +194,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:ruimeiCenter]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; }else if ([devicemodel.type isEqualToString:DECICE_TYPE_hotBar]) { @@ -239,7 +239,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:none]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; } @@ -256,7 +256,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:twocontrolCenter]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; @@ -276,7 +276,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:threeControlCenter]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; @@ -302,7 +302,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:fourControlCenter]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; }else if (timerAmount == 6){ @@ -314,7 +314,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app2=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:keliaicenterVC]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app2.window.rootViewController=nav; @@ -340,7 +340,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:XuToCenter]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; } @@ -358,7 +358,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:songNu]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; } @@ -398,7 +398,7 @@ UIApplication*app=[UIApplication sharedApplication]; AppDelegate*app1=(AppDelegate*)app.delegate; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:blackVC]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; } diff --git a/Ifish/Utinitys/IfishUtils/UINavigationBar+Background.m b/Ifish/Utinitys/IfishUtils/UINavigationBar+Background.m index 3aca7a0..225f751 100755 --- a/Ifish/Utinitys/IfishUtils/UINavigationBar+Background.m +++ b/Ifish/Utinitys/IfishUtils/UINavigationBar+Background.m @@ -24,10 +24,10 @@ static char overlayKey; - (void)cnSetBackgroundColor:(UIColor *)backgroundColor { if (!self.overlay) { - [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; + [self setClearNav]; self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -20, [UIScreen mainScreen].bounds.size.width, CGRectGetHeight(self.bounds) + 20)]; if (@available(iOS 11.0, *)) { - self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -44, [UIScreen mainScreen].bounds.size.width, CGRectGetHeight(self.bounds) + 44)]; + self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -64, [UIScreen mainScreen].bounds.size.width, CGRectGetHeight(self.bounds) + 64)]; } else { self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, -20, [UIScreen mainScreen].bounds.size.width, CGRectGetHeight(self.bounds) + 20)]; } @@ -42,17 +42,30 @@ static char overlayKey; - (void)cnReset { - [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; + [self setClearNav]; [self.overlay removeFromSuperview]; self.overlay = nil; } -(void)setClearNav { - - [self setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]; - //设置那条横线直接隐藏 - self.shadowImage = [[UIImage alloc] init]; + NSDictionary *dic = @{NSForegroundColorAttributeName : [UIColor whiteColor], + NSFontAttributeName : [UIFont systemFontOfSize:19]}; + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *barApp = [UINavigationBarAppearance new]; + barApp.backgroundColor = [UIColor clearColor]; + barApp.titleTextAttributes = dic; + barApp.backgroundEffect = nil; + barApp.shadowColor = nil; + self.scrollEdgeAppearance = nil; + self.standardAppearance = barApp; + }else{ + self.titleTextAttributes = dic; + [self setShadowImage:[UIImage new]]; + [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; + } + //透明 + self.translucent = YES; if (self.overlay) { [self.overlay removeFromSuperview]; self.overlay = nil; @@ -62,17 +75,178 @@ static char overlayKey; -(void)resetBackgroundImage{ - [self setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + + [self setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; } -(void)setWhiteNav { - [self setBackgroundImage:[UIImage imageNamed:@"blackbar_white.png"] forBarMetrics:UIBarMetricsDefault]; + + [self setNavbgImage:[UIImage imageNamed:@"blackbar_white.png"]]; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; } + + +#pragma mark - 私有 ++ (UIColor *)colorWithHexString:(NSString *)stringToConvert +{ + if ([stringToConvert hasPrefix:@"#"]) + { + stringToConvert = [stringToConvert substringFromIndex:1]; + } + float alpha=1.0; + if (stringToConvert.length>6&&![stringToConvert hasPrefix:@"0x"])//含有透明度 + { + NSString*alphaString=[stringToConvert substringToIndex:2]; + NSScanner *alphaScanner = [NSScanner scannerWithString:alphaString]; + unsigned hex; + + if (![alphaScanner scanHexInt:&hex]) + { + alpha=1.0; + } + else + { + const char *hexChar = [alphaString cStringUsingEncoding:NSUTF8StringEncoding]; + int hexNumber; + sscanf(hexChar, "%x", &hexNumber); + + alpha=hexNumber/255.0; + + } + } + + NSScanner *scanner = [NSScanner scannerWithString:stringToConvert]; + unsigned hexNum; + + if (![scanner scanHexInt:&hexNum]) + { + return [UIColor clearColor]; + } + + return [UIColor \ + colorWithRed:((float)((hexNum & 0xFF0000) >> 16))/255.0 \ + green:((float)((hexNum & 0xFF00) >> 8))/255.0 \ + blue:((float)(hexNum & 0xFF))/255.0 alpha:alpha]; +} ++ (UIImage *)createImageWithColor:(UIColor *)color +{ + CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); + UIGraphicsBeginImageContext(rect.size); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextSetFillColorWithColor(context, [color CGColor]); + CGContextFillRect(context, rect); + UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return theImage; +} + +- (void)setNavbgColorStr:(NSString *)colorStr +{ + + UIImage *image = [self.class createImageWithColor:[self.class colorWithHexString:colorStr]]; + [self setNavbgImage:image]; +} +- (void)setNavbgColor:(UIColor *)color +{ + UIImage *image = [self.class createImageWithColor:color]; + [self setNavbgImage:image]; +} +- (void)setNavbgImage:(UIImage *)image +{ + + if (image) { + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *apperar = [self getNavgationAppearanceWithNavgationController:self]; + apperar.backgroundImage = image; + apperar.backgroundImageContentMode=UIViewContentModeScaleAspectFill; + self.standardAppearance = apperar; + self.scrollEdgeAppearance = apperar; + }else{ + [self setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; + } + } +} +-(UIImage*)getNaveImage +{ + + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *apperar = [self getNavgationAppearanceWithNavgationController:self]; + return apperar.backgroundImage; + }else{ + + return [self + backgroundImageForBarMetrics:UIBarMetricsDefault]; + } + + return nil; +} + +- (UINavigationBarAppearance *)getNavgationAppearanceWithNavgationController:(UINavigationBar *)bar +API_AVAILABLE(ios(13.0)){ + if (@available(iOS 15.0, *)) { + if (bar.standardAppearance) { + return bar.standardAppearance; + } + + if (bar.scrollEdgeAppearance) { + return bar.scrollEdgeAppearance; + } + + return [[UINavigationBarAppearance alloc] init]; + } + return nil; +} + +- (void)setNavTitleColor:(UIColor *)color +{ + + if (color ) { + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *apperar = [self getNavgationAppearanceWithNavgationController:self]; + apperar.titleTextAttributes = @{NSForegroundColorAttributeName:color}; + self.standardAppearance = apperar; + self.scrollEdgeAppearance = apperar; + }else{ + self.titleTextAttributes = @{NSForegroundColorAttributeName:color}; + } + + } +} + + +- (void)setNavTitleFont:(UIFont *)font +{ + if (font ) { + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *apperar = [self getNavgationAppearanceWithNavgationController:self]; + apperar.titleTextAttributes = @{NSFontAttributeName:font}; + self.standardAppearance = apperar; + self.scrollEdgeAppearance = apperar; + }else{ + self.titleTextAttributes = @{NSFontAttributeName:font}; + } + + } +} +- (void)setNavTitleTextAttributes:(NSDictionary*)attribute +{ + + if (attribute) { + if (@available(iOS 15.0, *)) { + UINavigationBarAppearance *apperar = [self getNavgationAppearanceWithNavgationController:self]; + apperar.titleTextAttributes = attribute; + self.standardAppearance = apperar; + self.scrollEdgeAppearance = apperar; + }else{ + self.titleTextAttributes = attribute; + } + + } +} @end diff --git a/Ifish/ViewController.m b/Ifish/ViewController.m index 16374df..5dc256f 100644 --- a/Ifish/ViewController.m +++ b/Ifish/ViewController.m @@ -72,7 +72,7 @@ [_indicatorView stopAnimating]; DisconnectNetController *connectVC =[[DisconnectNetController alloc] init]; UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:connectVC]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; [UIApplication sharedApplication].delegate.window.rootViewController=nav; }]; @@ -230,7 +230,7 @@ DisconnectNetController*disconectvc=[[DisconnectNetController alloc]init]; UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:disconectvc]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; //self.window.rootViewController=nav; [self presentViewController:nav animated:YES completion:nil]; diff --git a/Ifish/controllers/FishTinkController/maincontroller/RightViewController.m b/Ifish/controllers/FishTinkController/maincontroller/RightViewController.m index 47003b2..43ea693 100644 --- a/Ifish/controllers/FishTinkController/maincontroller/RightViewController.m +++ b/Ifish/controllers/FishTinkController/maincontroller/RightViewController.m @@ -756,7 +756,7 @@ NS_ENUM(NSInteger,deviceType){ // UIApplication*app=[UIApplication sharedApplication]; // AppDelegate*app1=app.delegate; // UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:ics]; -// [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; +// [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; // app1.window.rootViewController=nav; IfishP2PMonitorController *p2pVC=[[IfishP2PMonitorController alloc] init]; diff --git a/Ifish/controllers/IfishTabControllers/IfishADTimerViewController.m b/Ifish/controllers/IfishTabControllers/IfishADTimerViewController.m index b7ba83e..0e53d7e 100644 --- a/Ifish/controllers/IfishTabControllers/IfishADTimerViewController.m +++ b/Ifish/controllers/IfishTabControllers/IfishADTimerViewController.m @@ -67,7 +67,7 @@ [_indicatorView stopAnimating]; DisconnectNetController *connectVC =[[DisconnectNetController alloc] init]; UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:connectVC]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; [UIApplication sharedApplication].delegate.window.rootViewController=nav; }]; diff --git a/Ifish/controllers/IfishTabControllers/IfishMianTabViewController.m b/Ifish/controllers/IfishTabControllers/IfishMianTabViewController.m index bdac196..bcfe6cf 100644 --- a/Ifish/controllers/IfishTabControllers/IfishMianTabViewController.m +++ b/Ifish/controllers/IfishTabControllers/IfishMianTabViewController.m @@ -14,6 +14,7 @@ #import "IfishUserObsever.h" #import "UITabBar+addRedPointBadge.h" #import "LoveFishLiveListBaseViewController.h" +#import "UIViewController+Navgation.h" @interface IfishMianTabViewController () @property (nonatomic,strong) NSArray *navigationHandlers; @@ -132,7 +133,7 @@ extern BOOL launchedByNotification; //nav.navigationBar.backgroundColor = [UIColor redColor]; //[nav.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; //直接切图 或扩展导航UINavigationBar+Background - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; NSString *title=titles[i]; vc.title = title; @@ -144,6 +145,9 @@ extern BOOL launchedByNotification; @{NSFontAttributeName:[UIFont systemFontOfSize:19], NSForegroundColorAttributeName:[UIColor whiteColor]}]; + [nav setNavTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19], + + NSForegroundColorAttributeName:[UIColor whiteColor]}]; //IOS7后本项目可不做IOS7 以下处理 UIImage *imgnomal=[UIImage imageNamed:ImageArr[i]]; @@ -178,7 +182,7 @@ extern BOOL launchedByNotification; } [VCArr1 addObject:nav]; } - + self.tabBar.backgroundColor=[UIColor whiteColor]; self.viewControllers=VCArr1; if (launchedByNotification) { diff --git a/Ifish/controllers/IfishTabControllers/我的/mineControllers/IfishSetViewController.m b/Ifish/controllers/IfishTabControllers/我的/mineControllers/IfishSetViewController.m index 3f090ce..d1e6cc0 100644 --- a/Ifish/controllers/IfishTabControllers/我的/mineControllers/IfishSetViewController.m +++ b/Ifish/controllers/IfishTabControllers/我的/mineControllers/IfishSetViewController.m @@ -171,7 +171,7 @@ extern BOOL firstLogIn; LogInViewController*logIn=[[LogInViewController alloc]init]; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:logIn]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; [UIApplication sharedApplication].delegate.window.rootViewController = nav; } diff --git a/Ifish/controllers/IfishTabControllers/设备/IfishDeviceViewController.m b/Ifish/controllers/IfishTabControllers/设备/IfishDeviceViewController.m index 988cb4b..f54318d 100644 --- a/Ifish/controllers/IfishTabControllers/设备/IfishDeviceViewController.m +++ b/Ifish/controllers/IfishTabControllers/设备/IfishDeviceViewController.m @@ -768,11 +768,11 @@ Assign BOOL isPush; -(void)initUI{ self.automaticallyAdjustsScrollViewInsets = NO; - + self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]; [self.tableView registerNib:[UINib nibWithNibName:@"TabBarDeviceShouYeCell" bundle:nil] forCellReuseIdentifier:@"TabBarDeviceShouYeCell"]; [self.tableView registerNib:[UINib nibWithNibName:@"TabbarDeiceSecdCell" bundle:nil] forCellReuseIdentifier:@"TabbarDeiceSecdCell"]; //CGFloat sapce=TabContentHeaght*0.011;//20/1776 - self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]; + self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; diff --git a/Ifish/controllers/leftcontrollers/SetViewController.m b/Ifish/controllers/leftcontrollers/SetViewController.m index 4b0401c..071629a 100644 --- a/Ifish/controllers/leftcontrollers/SetViewController.m +++ b/Ifish/controllers/leftcontrollers/SetViewController.m @@ -246,7 +246,7 @@ extern BOOL firstLogIn; LogInViewController*logIn=[[LogInViewController alloc]init]; UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:logIn]; - [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; + [nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]]; app1.window.rootViewController=nav; firstLogIn=NO;