zoukankan      html  css  js  c++  java
  • iOS自定义字体及类目 分类: ios技术 2015-05-15 16:34 195人阅读 评论(0) 收藏

    1:获取字体文件

    从各种渠道下载字体文件ttf, 网站或者从别的ipa里扣出来.(以fzltxh.ttf为例)

     

    2:将fzltxh.ttf文件拷贝到工程中

     

    3:在Info.plist中添加项:

    Fonts provided by application(UIAppFonts)  可以添加一个或多个item,

    如 item0 --  fzltxh.ttf

     

    4:找出真正的字体名称:

    因为使用字体时, 要使用字体的真实名称, 而不是文件名, 可以用以下代码来遍历当前设备可用的字体名称,

    再从中找出刚才添加的字体真实名称.

        
        NSArray *familyNames = [UIFont familyNames];
        for( NSString *familyName in familyNames )
        {
            printf( "Family: %s 
    ", [familyName UTF8String]);
            
            NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
            for( NSString *fontName in fontNames )
            {
                printf( "	Font: %s 
    ", [fontName UTF8String] );
            }
        }
    

      

     

    FZLTXHK--GBK1-0  这个就是此字体的真实使用名称.

     

    5:使用字体

    [UIFont fontWithName:@"FZLTXHK--GBK1-0" size:fontSize];
    

      

    6:统一替换

    如果想把旧工程的字体整体替换掉, 又不想改动已有代码, 可以重写 

    systemFontOfSize 方法.

    //
    //  UIFont+custom.h
    //  TuJing
    //
    //  Created by willbin on 15/1/13.
    //  Copyright (c) 2015年 willbin. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface UIFont (TJCustom)
    
    + (UIFont *)systemFontOfSize:(CGFloat)fontSize;
    
    @end
    

     

    //
    //  UIFont+custom.m
    //  TuJing
    //
    //  Created by willbin on 15/1/13.
    //  Copyright (c) 2015年 willbin. All rights reserved.
    //
    
    #import "UIFont+custom.h"
    
    @implementation UIFont (TJCustom)
    
    + (UIFont *)systemFontOfSize:(CGFloat)fontSize
    {
        return [UIFont fontWithName:@"FZLTXHK--GBK1-0" size:fontSize];
    }
    
    @end
    

      

     

    这样的话, 原先写的 

    systemFontOfSize 方法都会用新方法代替, 从而实现整体替换的效果.

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    ActionForm补充
    ActionForward
    struts模式匹配
    ActionMapping
    struts1.x的国际化
    DispatchAction
    ActionForm作为类型转换
    struts自定义异常
    hibernate核心接口
    Visual C# 2008+SQL Server 2005 数据库与网络开发 9.5 小结
  • 原文地址:https://www.cnblogs.com/liuqixu/p/4683973.html
Copyright © 2011-2022 走看看