Set the navigation bar controller background color
Effect
Description
1. Remove the black line from the original navigation bar controller
2. Can customize the background transparency
Source
////APPDELEGATE.M//Uinavigationcontrollerset////Created by youxianming on 15/9/1.//Copyright (c) 2015 youxianming. All rights reserved.//#import "AppDelegate.h"#import "ViewController.h"#import "uicolor+createimage.h"@interfaceappdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Self.window=[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; Self.window.backgroundColor=[Uicolor Whitecolor]; Viewcontroller*VC =[[Viewcontroller alloc] init]; Uinavigationcontroller*NC =[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:VC]; [Nc.navigationbar Setbackgroundimage:[[[uicolor Redcolor] Colorwithalphacomponent:0.5f] Imagewithframe:cgrectmake (0,0,Ten,Ten)] Forbarposition:uibarpositionany Barmetrics:uibarmetricsdefaul T]; [Nc.navigationbar Setshadowimage:[[uicolor Clearcolor] Imagewithframe:cgrectmake (0,0,Ten,Ten)]]; Self.window.rootViewController=NC; [Self.window makekeyandvisible]; returnYES;}- (void) Applicationwillresignactive: (UIApplication *) Application {//Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state. //Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void) Applicationdidenterbackground: (UIApplication *) Application {//Use the method to release the shared resources, save user data, invalidate timers, and store enough application state in Formation to the restore your application to the it is terminated later. //If Your application supports background execution, this method is called instead of Applicationwillterminate:when th E user quits.}- (void) Applicationwillenterforeground: (UIApplication *) Application {//Called as part of the transition from the background to the inactive state; Here you can undo many of the changes mad E on entering the background.}- (void) Applicationdidbecomeactive: (UIApplication *) Application {//Restart Any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.}- (void) Applicationwillterminate: (UIApplication *) Application {//Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.}@end
// // uicolor+createimage.h// uitabbarcontrollericon / /// Created by youxianming on 15/8/31. // Copyright (c) 2015 youxianming. All rights reserved. // #import <UIKit/UIKit.h>@interface uicolor (createimage)-(UIImage *) Imagewithframe: (CGRect) frame; @end
////UICOLOR+CREATEIMAGE.M//Uitabbarcontrollericon////Created by youxianming on 15/8/31.//Copyright (c) 2015 youxianming. All rights reserved.//#import "uicolor+createimage.h"@implementationUicolor (createimage)-(UIImage *) Imagewithframe: (CGRect) frame {UIImage*image =Nil; if(self) {UIView*view =[[UIView alloc] initwithframe:frame]; View.backgroundcolor=Self ; Uigraphicsbeginimagecontext (view.frame.size); [[View layer] renderincontext:uigraphicsgetcurrentcontext ()]; Image=Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); } returnimage;}@end
Details
Set the navigation bar controller background color