美文网首页
自定义导航栏

自定义导航栏

作者: doubleJJ | 来源:发表于2016-07-08 17:12 被阅读27次

- (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; //隐藏返回按钮

}

相关文章

网友评论

      本文标题:自定义导航栏

      本文链接:https://www.haomeiwen.com/subject/aylrjttx.html