Statusbar--navbar---CustomButton

Source: Internet
Author: User
Tags set background

Http://www.cnblogs.com/ihojin/p/ios7-statusbarstyle-in-viewcontroller.html

Rewrite NavBar to set the status bar in other files has no use, only in the NavBar settings to use

In my IPhone application built with Xcode 5 for IOS 7 I set uiviewcontrollerbasedstatusbarappearance=yes in Info.plist D in my Viewcontroller I has this code:

-(Uistatusbarstyle) preferredstatusbarstyle{    returnuistatusbarstylelightcontent;}
And it can be used in plsit.

[UIApplication sharedapplication].statusbarstyle = uistatusbarstylelightcontent;

Add this code and you're ready to go.

-----------------------------Custom Button----------------------------

Custombutton.m

Buyinsurance

Created by lightning on 15/2/11.

Copyright (c) 2015 No9527. All rights reserved.

#define TITLEBUTTONIMAGEW length_4inch_adapted (10)

#import "CustomButton.h"

@implementation CustomButton

-(ID) initWithFrame: (CGRect) frame{

self = [super Initwithframe:frame];

if (self) {

Initialization code

Text color

[Self Settitlecolor:colori (0XFFFFFF) forstate:uicontrolstatenormal];

Do not make ImageView gray when highlighting

self.adjustsimagewhenhighlighted = NO;

Self.imageView.contentMode = Uiviewcontentmodecenter;

Set text right-aligned

Self.titleLabel.textAlignment = Nstextalignmentleft;

Background

Self.titleLabel.font = Font_4inch_adapted_width (16);

[Self Settitlecolor:colori (0XFFFFFF) forstate:uicontrolstatenormal];

[Self Settitlecolor:colori (0xadadad) forstate:uicontrolstatehighlighted];

}

return self;

}

-(CGRect) Imagerectforcontentrect: (CGRect) contentrect{

CGFloat imagey = 0;

CGFloat Imagew = Titlebuttonimagew;

CGFloat ImageX = 0;

CGFloat Imageh = self.height;

Return CGRectMake (ImageX, Imagey, Imagew, Imageh);

}

-(CGRect) Titlerectforcontentrect: (CGRect) Contentrect

{

CGFloat Titlex = Titlebuttonimagew + length_4inch_adapted (5);

CGFloat Titley = 0;

CGFloat Titlew = Self.width-titlebuttonimagew;

CGFloat Titleh = self.height;

Return CGRectMake (Titlex, Titley, Titlew, Titleh);

}

@end

------------------------------------rewrite NavBar------------------------

//

Basenavviewcontroller.m

Buyinsurance

//

Created by lightning on 15/2/11.

Copyright (c) 2015 No9527. All rights reserved.

//

#import "BaseNavViewController.h"

#import "CustomButton.h"

@interface Basenavviewcontroller ()

@end

@implementation Basenavviewcontroller

+ (void) initialize{

Set the navigation bar theme

[Self setupnavtheme];

}

#pragma mark-Set the navigation bar theme

+ (void) setupnavtheme{

1. Get Appearance Object

Uinavigationbar *navbar = [Uinavigationbar appearance];

Set background

[NavBar setbackgroundimage:[uiimage imageautomaticname:@ "Navigationbar_background"] forbarmetrics: Uibarmetricsdefault];

Set text

Nsdictionary *textatts = [self settitletextfont:font_4inch_adapted_width (+) Fontcolor:[uicolor WhiteColor]];

[NavBar Settitletextattributes:textatts];

}

Status bar

-(Uistatusbarstyle) preferredstatusbarstyle{

return uistatusbarstylelightcontent;

}

Set text

+ (Nsdictionary *) Settitletextfont: (Uifont *) font fontcolor: (Uicolor *) color{

Nsmutabledictionary *textatts = [Nsmutabledictionary dictionary];

Set Text color

Textatts[nsforegroundcolorattributename] = color;

Remove Shadows

Nsshadow *shadow = [[Nsshadow alloc] init];

Shadow.shadowoffset = cgsizemake (0, 0);

Shadow.shadowcolor = color;

Blur degree

Shadow.shadowblurradius = 0;

Textatts[nsshadowattributename] = shadow;

Set font

Textatts[nsfontattributename] = font;

return Textatts;

}

Set the navigation bar button theme

#pragma mark sets the navigation bar button theme

+ (void) setupitemtheme{

1. Get Appearance Object

Uibarbuttonitem *item = [Uibarbuttonitem appearance];

2. Setting the background

Set text

Nsdictionary *attrfont = [self settitletextfont:font_4inch_adapted_width (+) Fontcolor:[uicolor OrangeColor]];

[item Settitletextattributes:attrfont Forstate:uicontrolstatenormal];

Nsmutabledictionary *hightattrfont = [Nsmutabledictionary dictionary];

Hightattrfont.dictionary = Attrfont;

Hightattrfont[nsforegroundcolorattributename] = [Uicolor colorwithred:0.5 green:0.5 blue:0.5 alpha:0.3];

[item Settitletextattributes:hightattrfont forstate:uicontrolstatehighlighted];

Nsmutabledictionary *disabledlattrfont = [Nsmutabledictionary dictionary];

Disabledlattrfont.dictionary = Attrfont;

Disabledlattrfont[nsforegroundcolorattributename] = [Uicolor colorwithred:0.9 green:0.9 blue:0.9 alpha:0.2];

[item Settitletextattributes:hightattrfont forstate:uicontrolstatedisabled];

}

-(void) viewdidload

{

[Super Viewdidload];

if (IOS7) {///iOS 6 not supported

Clear the gesture recognizer's agent, and you can recover a slide to remove the controller

Self.interactivePopGestureRecognizer.delegate = nil;

}

[Self statusBar];

}

-(void) statusbar{

UIView *statusbar = [[UIView alloc] Initwithframe:cgrectmake (0,-20, 0, 0)];

Statusbar.size = [UIApplication sharedapplication].statusbarframe.size;

[Self.navigationbar Addsubview:statusbar];

Statusbar.backgroundcolor = [Uicolor Yellowcolor];

}

-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated

{

if (Self.viewControllers.count > 0) {

The Back button of the top left foot

Nsinteger count = self.viewcontrollers.count-1;

Uiviewcontroller *VC = Self.viewcontrollers[count];

uiimage* backimage = [UIImage imageautomaticname:@ "Arrow-left-default"];

CGRect backframe = CGRectMake (0,0,length_4inch_adapted (+), length_4inch_adapted (30));

custombutton* backbutton= [[CustomButton alloc] initwithframe:backframe];

[Backbutton setimage:backimage Forstate:uicontrolstatenormal];

Backbutton.backgroundcolor = [Uicolor Yellowcolor];

[Backbutton SetTitle:vc.title Forstate:uicontrolstatenormal];

Backbutton.imageedgeinsets = Uiedgeinsetsmake (0, length_4inch_adapted (-30), 0, 0);

Backbutton.titleedgeinsets = Uiedgeinsetsmake (0, length_4inch_adapted (-15), 0, 0);

BackButton.titleLabel.font = Font_4inch_adapted_width (16);

[Backbutton addtarget:self Action: @selector (back) forcontrolevents:uicontroleventtouchupinside];

uibarbuttonitem* Leftbarbuttonitem = [[Uibarbuttonitem alloc] Initwithcustomview:backbutton];

ViewController.navigationItem.leftBarButtonItem = Leftbarbuttonitem;

}

[Super Pushviewcontroller:viewcontroller animated:animated];

}

/**

* Return

*/

-(void) back

{

[Self popviewcontrolleranimated:yes];

}

@end

Statusbar--navbar---CustomButton

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.