自定义导航栏

2016-07-08  本文已影响27人  doubleJJ

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

}

上一篇 下一篇

猜你喜欢

热点阅读