As I support Colin's answer, I want to give a additional hint to customize the appearance of an Uinavigationbar inclu Ding the alpha.
The trick is to use uiappearance for your navigationbar. This enables assign a UIImage to your Navigationbar ' s backgroundimage. You can generate these uiimages programmatically and use for that uicolors and set the colors ' Alpha Properties a s you want. I ' ve done this in one of my own applications and it works as expected.
Here I give you some code snippets:
-
e.g. in your. APPDELEGATE.M add these lines in Didfinishlaunchingwithoptions
-
//Create background images for the navigation barUIImage *gradientimage44 = nil;//Replace "nil" with your method to programmatically create a UIImage object with transparent colors for portrait Orient ationUIImage *gradientimage32 = nil;//Replace "nil" with your method to programmatically create a UIImage object with transparent colors for landscape Orien Tation//Customize the appearance of Uinavigationbar[[Uinavigationbar appearance] setbackgroundimage:gradientimage44 Forbarmetrics:uibarmetricsdefault]; [[Uinavigationbar appearance] setbackgroundimage:gradientimage32 Forbarmetrics:uibarmetricslandscapephone]; [[Uinavigationbar appearance] setbarstyle:uibarstyledefault];
2.Implement convenience methods to programmatically creates UIImage objects, e.g. create a new category for UIImage:
-
//Uiimage+initwithcolor.h//#import<UIKit/UIKit.h>@interfaceUIImage (Initwithcolor)//programmatically create an UIImage with 1 pixel of a given color+ (UIImage *) Imagewithcolor: (Uicolor *) color;//implement additional methods here to create images with gradients etc.//[..]@end//UIIMAGE+INITWITHCOLOR.M//#import "Uiimage+initwithcolor.h"#import<QuartzCore/QuartzCore.h>@implementationUIImage (Initwithcolor)+ (UIImage *) Imagewithcolor: (Uicolor *) color{CGRect rect= CGRectMake (0,0,1,1); //Create a 1 by 1 pixel contextUigraphicsbeginimagecontextwithoptions (Rect.size, NO,0); [Color Setfill]; Uirectfill (rect); UIImage*image =Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); returnimage;}
3.re-work your image creation in 1. (#import "Uiimage+initwithcolor.h" in APPDELEGATE.M and replace the "nil" s):
-
UIImage *gradientimage44 = [UIImage imagewithcolor:[uicolor colorwithred: 1.0 Green:0.0 Blue:1.0 Alpha:0.2]]; *GRADIENTIMAGE32 = [UIImage imagewithcolor:[uicolor colorwithred: 1.0 Green: 0.0 Blue:1.0 Alpha:0.2]];
Set transparency with a picture as a background
iOS Set nav bar transparency