IOS Custom status bar and navigation bar detailed introduction _ios

Source: Internet
Author: User

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;

 }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.