Giter VIP home page Giter VIP logo

mzfontimport's Introduction

MZFontImport

前言

在iOS开发过程中,我们有时会需要使用一些炫酷或特定字体,那么就需要导入三方自定义字体来实现功能。

下载自定义字体

对应的字体请自行百度下载,目前大部分字体商用均需获取授权,请注意不要侵权使用

导入自定义字体

  1. 将字体文件拖入工程
    image
  2. 在Info中添加Fonts provided by application选项,并添加子项,填入你导入的自定义字体名称,我这里填入let.ttf
    image
  3. 找到对应的字体名称
  • 本地打开字体库文件,查看标题上的字体库名称
    image
  • 使用代码找到对应的字体family和name
    for (NSString *fontFamilyName in [UIFont familyNames]) {
        NSLog(@"family:'%@'\n",fontFamilyName);
        for (NSString *fontName in [UIFont fontNamesForFamilyName:fontFamilyName]) {
            NSLog(@"\tfont:'%@'\n",fontName);
        }
        NSLog(@"-------------\n");
    }
  • 查看log搜索我们在本地打开字体库时标题上的字体库名称(Let's go Digital),找到对应的字体名称(LetsgoDigital-Regular)
    image
  1. 使用对应的Font
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, self.view.bounds.size.width-40, 50)];
    label.text = @"asdff443434";
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont fontWithName:@"LetsgoDigital-Regular" size:40];
    [self.view addSubview:label];

image

  1. 附上demo链接

mzfontimport's People

Contributors

1691665955 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.