你如何在Swift中设置字体样式? [英] How do you stylize a font in Swift?

查看:476
本文介绍了你如何在Swift中设置字体样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Swift开发,它进展顺利。我遇到的一个问题是如何在语言中以编程方式设置字体样式。

I'm trying out developing for Swift, it's going pretty well. One of the issues I'm having is finding out how to stylize fonts programmatically in the language.

例如,在这个标签中,我编写了以下代码,例如,我如何制作Helvetica Neue Ultralight?

For example in this label I wrote the code below for, how can I make it Helvetica Neue Ultralight for example?

label.font = UIFont (name: "Helvetica Neue", size: 30)


推荐答案

我假设这是一个自定义字体。对于任何自定义字体,这都是你做的。

I am assuming this is a custom font. For any custom font this is what you do.


  1. 首先下载并在Xcode中将你的字体文件添加到你的项目
    (这些文件也应该出现在目标 - >构建阶段 - >复制捆绑资源中。)

  1. First download and add your font files to your project in Xcode (The files should appear as well in "Target -> Build Phases -> Copy Bundle Resources").

在Info.plist文件中添加密钥应用程序提供的字体,类型为数组。

In your Info.plist file add the key "Fonts provided by application" with type "Array".

对于要添加到项目中的每种字体,请为您创建的数组创建项目使用文件的全名,包括其扩展名(例如HelveticaNeue-UltraLight.ttf)。
保存您的Info.plist文件。

For each font you want to add to your project, create an item for the array you have created with the full name of the file including its extension (e.g. HelveticaNeue-UltraLight.ttf). Save your "Info.plist" file.

label.font = UIFont(名称:HelveticaNeue-UltraLight,尺寸:30)

这篇关于你如何在Swift中设置字体样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆