自定义导航栏

- (void)customNavigation{

UILabel*titleLabel = [[UILabelalloc]initWithFrame:CGRectMake(0,0,200,44)];

titleLabel.font= [UIFontsystemFontOfSize:17];

titleLabel.textColor= [UIColor whiteColor];

titleLabel.textAlignment=NSTextAlignmentCenter;

titleLabel.text=@"注册账号";

self.navigationItem.titleView= titleLabel;

//左边item

UIButton*leftBtn = [[UIButtonalloc]initWithFrame:CGRectMake(0,0,44,44)];

UIBarButtonItem*leftItem = [[UIBarButtonItemalloc]initWithCustomView:leftBtn];

//右边item

UIButton*rightBtn = [[UIButtonalloc]initWithFrame:CGRectMake(0,0,44,44)];

[rightBtnsetTitle:@"登录"forState:UIControlStateNormal];

rightBtn.titleLabel.font= [UIFontsystemFontOfSize:15];

[rightBtnsetTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

[rightBtnaddTarget:selfaction:@selector(login)forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem*righItem = [[UIBarButtonItemalloc]initWithCustomView:rightBtn];

self.navigationItem.leftBarButtonItem= leftItem;

self.navigationItem.rightBarButtonItem= righItem;

//self.navigationItem.hidesBackButton = YES; //隐藏返回按钮

}

你可能感兴趣的:(自定义导航栏)