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版本就可以已经有了。具体效果如下图所示:

  • 相关阅读:
    0Day – 2011.01.26
    JQuery_PHP 开始新的旅途
    0Day – 2011.01.25
    0Day – 2011.02.04
    Delphi 必须的一致.
    0Day – 2011.01.28
    0Day – 2011.02.23[From B4A]
    足球 看球悲惨的回忆.
    Delphi – EurekaLog6.1.01Ent下载地址
    ubuntu 拨号
  • 原文地址:https://www.cnblogs.com/liuxp1990/p/3485261.html
Copyright © 2011-2022 走看看