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

  • 相关阅读:
    关于jQuery中click&live&on中的坑
    redis 主从配置和集群配置
    python 搭建redis集群
    事件冒泡及事件委托的理解(JQuery Dom操作)
    python中import和from-import的区别
    python中赋值-浅拷贝-深拷贝之间的关系
    学生管理系统.JavaScript
    学生管理系统.c
    电梯演讲与原型展示
    软件需求分析
  • 原文地址:https://www.cnblogs.com/liuxp1990/p/3485261.html
Copyright © 2011-2022 走看看