A situation is encountered in real-world development. The UI will make the navigation bar transparent, and when it slides, it becomes visible. It's like this when it's opaque.
It's pretty ugly.
So to make a transparent navigation bar, you need to know a method, a property
At this point, UIImage looks like it has to be a drawing.
-(UIImage *) Imagewithcolor: (Uicolor *) color { = CGRectMake (0011 ); Uigraphicsbeginimagecontext (rect.size); = Uigraphicsgetcurrentcontext (); [Color Setfill]; Cgcontextfillrect (context, rect); *imgae = uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); return Imgae;}
Of course, you can also add classes to UIImage
Uiimage+colorimge.h
#import <UIKit/UIKit.h>@interface UIImage (colorimge)+ (UIImage *) Imagewithcolor: (Uicolor *) color Andsize: (cgsize) size; @end
Uiimage+colorimge.m
#import " uiimage+colorimge.h " @implementation UIImage (colorimge) + (UIImage *) Imagewithcolor: (uicolor *) color andsize: (cgsize) size {cgrect rect = CGRectMake (0 , 0 Size.width, Size.Height); Uigraphicsbeginimagecontext (rect.size); Cgcontextref context = Uigraphicsgetcurrentcontext (); Cgcontextsetfillcolorwithcolor (context, [color Cgcolor]); Cgcontextfillrect (context, rect); UIImage *image = Uigraphicsgetimagefromcurrentimagecontext (); Cgcontextaddellipseinrect (context, rect); Uigraphicsendimagecontext (); return image; @end
So you can initialize a uiimage directly.
Then we can make the navigation transparent.
Effect
When you want to be able to slide the color gradually similar
Need to be
-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView; The method is a fuss. Because TableView inherits from ScrollView.
In this method, the contentoffset.y of TableView is judged. Look at the code first
Current transparency = (beginning of tableview.contentoffset.y-tableview.contentoffset.y)/(completely opaque end point + tableview.contentoffset.y start) Generally do not make changes to the beginning of the TABLEVIEW.CONTENTOFFSET.Y is 0, the complete opacity of the end is to see your mood sliding how far when the navigation bar full color.
If you have time, you can do the encapsulation. have different effects in different situations
IOS (nav bar) NavBar Transparent