zoukankan      html  css  js  c++  java
  • 在iPhone应用中使用自定义字体

    iPhone系统的字体数量有限,并且多数对中文没有效果,下面介绍两种解决办法

    方法1

      添加对应的字体(.ttf.odf)到工程的resurce,使用cocos2d中的FontLabel库,FontLabel继承于UILabel,象UILabel一样使用就好了

      fontName直接使用添加的资源名字即可

    方法2;

      1,添加对应的字体(.ttf.odf)到工程的resurce,例如simkai.ttf

      2,在info.plist中添加一项 Fonts provided by application (item0对应的valuesimkai.ttf,添加多个字体依次添加就可以了)

      3,使用时 aLabel.font=[UIFont fontWithName:@"XXX" size:30]; 注意XXX不一定是simkai,这里是KaiTi_GB2312(中文楷体),你可以通过下面的方法遍历所有字体

        //显示系统中所有的字体
        NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]]; 
        NSArray *fontNames; 
        NSInteger indFamily, indFont; 
        for (indFamily=0; indFamily<[familyNames count]; ++indFamily) 
        { 
                NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]); 
                fontNames = [[NSArray alloc] initWithArray: [UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]]; 
                for (indFont=0; indFont<[fontNames count]; ++indFont) 
                { 
                    NSLog(@" Font name: %@", [fontNames objectAtIndex:indFont]); 
                } 
                [fontNames release]; 
        } 
        [familyNames release]; 

    其中添加的simkai.ttf对应的字体就是KaiTi_GB2312 

      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 50)]; 
      label.font = [UIFont fontWithName:@"KaiTi_GB2312" size:30]; 
      label.text = @"中文楷体"; 
      [self.view addSubview:label]; 
      [label release];

     

  • 相关阅读:
    装饰器
    静态文件---访问图片
    用户登录
    读写Session
    windows进入指定目录
    Response 与 Cookie
    处理HTTP请求
    pycharm中指定ip和端口
    python爬虫学习(三):使用re库爬取"淘宝商品",并把结果写进txt文件
    python爬虫学习(二):定向爬虫例子-->使用BeautifulSoup爬取"软科中国最好大学排名-生源质量排名2018",并把结果写进txt文件
  • 原文地址:https://www.cnblogs.com/foxmin/p/2483532.html
Copyright © 2011-2022 走看看