iOS开发之Navigation(导航栏)补充

1.自定义导航栏文字
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0 , 40, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];  //设置Label背景透明
    titleLabel.font = [UIFont boldSystemFontOfSize:20];  //设置文本字体与大小
    titleLabel.textColor = [UIColor blackColor];  //设置文本颜色
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"逛市场";  //设置标题
    self.navigationItem.titleView = titleLabel;
2.导航栏渐变效果

主要代码就一句,滑动更改导航栏透明度

iOS开发之Navigation(导航栏)补充_第1张图片
Paste_Image.png

demo演示&&下载:
https://github.com/OwenJoe/navigationBar_ChangeAlpah.git

iOS开发之Navigation(导航栏)补充_第2张图片
导航栏渐变效果

3.如果碰到App的导航栏样式基本上不改变,我们可以在APPDelegate.m里边定义此方法.
iOS开发之Navigation(导航栏)补充_第3张图片
Paste_Image.png
#pragma mark -- 修改全局的导航栏样式
-(void)correctNavBarMethod{
    
    //定义全局的导航栏
    UINavigationBar *navBar = [UINavigationBar appearance];
    
    //改变背景颜色
    navBar.barTintColor = [UIColor colorWithRed:248.0/255 green:246.0/255 blue:248.0/255 alpha:1];
    
    //修改导航栏标题颜色,文字大小,文字种类
    [navBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:20],NSForegroundColorAttributeName:[UIColor blackColor]}];
    
    //修改文字
    UIBarButtonItem *barItem = [UIBarButtonItem appearance];
    [barItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor darkGrayColor]} forState:UIControlStateNormal];

}

4.设置导航栏中间的title/title变button

导航栏navigationBar中间变button====>跟方法一很类似
self.navigationItem.titleView =button;  
UIButton * button =[UIButton buttonWithType:UIButtonTypeCustom];  
button.frame=CGRectMake(20, 20, 100, 40);  
[button setTitle:@"1/3" forState:UIControlStateNormal];  
[button addTarget:self action:@selector(showAllQuestions:) forControlEvents:UIControlEventTouchUpInside];  
self.navigationItem.titleView =button;  

你可能感兴趣的:(iOS开发之Navigation(导航栏)补充)