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.导航栏渐变效果

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

Paste_Image.png

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

导航栏渐变效果

3.如果碰到App的导航栏样式基本上不改变,我们可以在APPDelegate.m里边定义此方法.
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;  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容