zoukankan      html  css  js  c++  java
  • ios7中修改导航栏标题的字体

    修改导航栏标题的字体

    跟iOS 6一样,我们可以使用导航栏的titleTextAttributes属性来定制导航栏的文字风格。在text attributes字典中使用如下一些key,可以指定字体、文字颜色、文字阴影色以及文字阴影偏移量:

    UITextAttributeFont – 字体key

    UITextAttributeTextColor – 文字颜色key

    UITextAttributeTextShadowColor – 文字阴影色key

    UITextAttributeTextShadowOffset – 文字阴影偏移量key

    如下代码所示,对导航栏的标题风格做了修改:

    1. NSShadow *shadow = [[NSShadow alloc] init]; 
    2.     shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8]; 
    3.     shadow.shadowOffset = CGSizeMake(0, 1); 
    4.     [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: 
    5.                                                            [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName, 
    6.                                                            shadow, NSShadowAttributeName, 
    7.                                                            [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]]; 

    运行效果如下图所示:

    修改导航栏标题为图片

    如果要想将导航栏标题修改为一个图片或者logo,那么只需要使用下面这行代码即可:

    1. self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"appcoda-logo.png"]]; 

    上面的代码简单的修改了titleView属性,将一个图片赋值给它。 注意:这不是iOS 7中的新功能,之前的iOS版本就可以已经有了。具体效果如下图所示:

  • 相关阅读:
    group by;having;order by
    oracle官方文档
    oracle正则表达式函数和正则表达式简介
    oracle系统函数
    oracle系统表
    windows搭建ftp服务器
    开机自动挂载
    linux修改设置ip地址
    My First Web Server
    为什么要写博客?
  • 原文地址:https://www.cnblogs.com/liuxp1990/p/3485261.html
Copyright © 2011-2022 走看看