IOS Custom status bar and navigation bar
Developing the iOS APP often changes the status bar and navigation bar according to the requirements, and there are several ways that you can look at.
Navigation bar Transparency
-(void) Viewwillappear: (BOOL) Animated {//viewwillappear Set transparent
[Super viewwillappear:animated];
[Self.navigationbar setbackgroundimage:[uiimage new] forbarmetrics:uibarmetricsdefault]; Fill a seat with an empty picture
[Self.navigationbar setshadowimage:[uiimage New]];//navibar bottom Seperatorline
}
-(void) Viewdiddisappear: (BOOL) Animated {//viewwillappear set restore
[Super viewdiddisappear:animated];
[Self.navigationbar Setbackgroundimage:nil Forbarmetrics:uibarmetricsdefault];
[Self.navigationbar setshadowimage:shadowimage];
}
Navigation bar Gradients
Barimageview = Self.navigationController.navigationBar.subviews.firstObject;
-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView {
CGFloat minalphaoffset =-;
CGFloat maxalphaoffset =;
CGFloat offset = scrollview.contentoffset.y;
CGFloat alpha = (offset-minalphaoffset)/(Maxalphaoffset-minalphaoffset); _barimageview.alpha = Alpha;
}
Status bar Font Color change
[UIApplication Sharedapplication].statusbarstyle = uistatusbarstyledefault;//black
[uiapplication Sharedapplication].statusbarstyle = uistatusbarstylelightcontent;//White
Navigation bar Hide
If the navigation bar customization is high and needs to be completely rewritten, you can hide the original navigation bar and define a new view
-(void) Viewwillappear: (BOOL) animated {[Super viewwillappear:animated];
Self.navigationController.navigationBarHidden = YES;
}-(void) Viewdiddisappear: (BOOL) animated {[Super viewdiddisappear:animated];
Self.navigationController.navigationBarHidden = NO; }-(void) Ys_initnavigationbar {self.navigationController.interactivePopGestureRecognizer.delegate = (id) self;//
Gestures that keep the right slider pop _navibar = [[UIView alloc] Initwithframe:cgrectmake (0, 0, Self.view.width, 64)];
_navibar.backgroundcolor = [Uicolor Whitecolor];
[Self.view Addsubview:_navibar];
UIView *line = [[UIView alloc] Initwithframe:cgrectmake (0, _navibar.height-0.5, Self.view.width, 0.5)];
Line.backgroundcolor = [Uicolor colorforhex:@ "f0f0f0"];
[_navibar Addsubview:line];
return Backbutton = [UIButton buttonwithtype:uibuttontypecustom];
Backbutton.frame = CGRectMake (0, 20, 44, 44);
[Backbutton addtarget:self Action: @selector (GoBack:) forcontrolevents:uicontroleventtouchupinside];
[Self.view Addsubview:backbutton]; Title Navilable = [[UIButton alloc] Initwithframe:cgrectmake (A., self.view.width-44*2, 44)];
Navilable.backgroundcolor = [Uicolor Clearcolor];
Navilable.font = [Uifont systemfontofsize:16];
Navilabel.textalignment = Nstextalignmentcenter;
[Self.view addsubview:navilable];
}-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview {//navigationbar change cgfloat = 0;
CGFloat Maxalphaoffset = 40;
CGFloat offset = scrollview.contentoffset.y;
CGFloat alpha = (offset-minalphaoffset)/(Maxalphaoffset-minalphaoffset);
_navibar.alpha = Alpha;
Navilabel.alpha = Alpha;
}