iPhone系统字体

发布于 2024-09-25 20:28:35 字数 66 浏览 6 评论 0 原文

iPhone 的默认系统字体名称是什么?

我想检索它以自定义 UIView

What is the name of the default system font on the iPhone?

I would like to retrieve this for customizing a UIView.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

゛清羽墨安 2024-10-02 20:28:35

让字体纯粹主义者感到高兴
iPhone系统无处不在
界面使用 Helvetica 或变体
其中。

初代 iPhone、iPhone 3G 和
iPhone 3GS系统界面使用
黑体。正如首先指出的
始终优秀的 DaringFireball,
iPhone 4 使用了经过细微修改的字体
称为“Helvetica Neue”。
DaringFireball 还指出,这
变化与 iPhone 4 有关
显示而不是 iOS 4
操作系统和旧款 iPhone
运行 iOS 4 的机型仍然使用
Helvetica 作为系统字体。

之前发布的 iPod 型号
iPhone 使用 Chicago、Espy Sans、
或 Myriad 并在之后使用 Helvetica
iPhone 发布。

来自 http://www .everyipod.com/iphone-faq/iphone-who-Designed-iphone-font-used-iphone-ringtones.html

对于iOS9,它已更改为旧金山。有关详细信息,请参阅 http://developer.apple.com/fonts

To the delight of font purists
everywhere, the iPhone system
interface uses Helvetica or a variant
thereof.

The original iPhone, iPhone 3G and
iPhone 3GS system interface uses
Helvetica. As first noted by the
always excellent DaringFireball, the
iPhone 4 uses a subtly revised font
called "Helvetica Neue."
DaringFireball also notes that this
change is related to the iPhone 4
display rather than the iOS 4
operating system and older iPhone
models running iOS 4 still use
Helvetica as the system font.

iPod models released prior to the
iPhone use either Chicago, Espy Sans,
or Myriad and use Helvetica after the
release of the iPhone.

From http://www.everyipod.com/iphone-faq/iphone-who-designed-iphone-font-used-iphone-ringtones.html

For iOS9 it has changed to San Francisco. See http://developer.apple.com/fonts for more info.

梦幻之岛 2024-10-02 20:28:35

如果您正在进行编程自定义,请不要对系统字体进行硬编码。使用 UIFont systemFontOfSize:UIFont boldSystemFontOfSize:UIFont italicSystemFontOfSize (Apple 文档)。

自 iOS 7 将系统字体更改为 Helvetica Neue 以来,这一点变得尤为重要。

自 iOS 9 以来,这一点变得尤其重要,iOS 9 再次将系统字体更改为 San Francisco。

If you're doing programatic customisation, don't hard code the system font. Use UIFont systemFontOfSize:, UIFont boldSystemFontOfSize: and UIFont italicSystemFontOfSize (Apple documentation).

This has become especially relevant since iOS 7, which changed the system font to Helvetica Neue.

This has become super especially relevant since iOS 9, which changed the system font again to San Francisco.

梦罢 2024-10-02 20:28:35

afaik iPhone 默认使用“Helvetica
< iOS 10

afaik iPhone uses "Helvetica" by default
< iOS 10

很酷又爱笑 2024-10-02 20:28:35

Swift

特定字体

在 Swift 中设置特定字体是这样完成的:

let myFont = UIFont(name: "Helvetica", size: 17)

如果您不知道名称,您可以获取可用字体名称的列表,如下所示:

print(UIFont.familyNames())

或者更详细的列表,如this:

for familyName in UIFont.familyNames() {
    print(UIFont.fontNamesForFamilyName(familyName))
}

但是系统字体随着iOS版本的不同而变化。所以最好动态获取系统字体。

系统字体

let myFont = UIFont.systemFontOfSize(17)

但是我们硬编码了尺寸。如果用户的眼睛不好,想要把字体调大怎么办?当然,您可以在应用程序中进行设置,让用户更改字体大小,但如果用户必须为手机上的每个应用程序单独执行此操作,这会很烦人。只需在常规设置中进行一项更改会更容易...

动态字体

let myFont = UIFont.preferredFont(forTextStyle: .body)

啊,现在我们为 文本样式 我们正在使用。这是设置字体的推荐方法。有关详细信息,请参阅支持动态类型

相关

Swift

Specific font

Setting a specific font in Swift is done like this:

let myFont = UIFont(name: "Helvetica", size: 17)

If you don't know the name, you can get a list of the available font names like this:

print(UIFont.familyNames())

Or an even more detailed list like this:

for familyName in UIFont.familyNames() {
    print(UIFont.fontNamesForFamilyName(familyName))
}

But the system font changes from version to version of iOS. So it would be better to get the system font dynamically.

System font

let myFont = UIFont.systemFontOfSize(17)

But we have the size hard-coded in. What if the user's eyes are bad and they want to make the font larger? Of course, you could make a setting in your app for the user to change the font size, but this would be annoying if the user had to do this separately for every single app on their phone. It would be easier to just make one change in the general settings...

Dynamic font

let myFont = UIFont.preferredFont(forTextStyle: .body)

Ah, now we have the system font at the user's chosen size for the Text Style we are working with. This is the recommended way of setting the font. See Supporting Dynamic Type for more info on this.

Related

吝吻 2024-10-02 20:28:35

您始终可以使用

UIFont *systemFont = [UIFont systemFontOfSize:12];
NSLog(@"what is it? %@ %@", systemFont.familyName, systemFont.fontName);

答案是:

最高 iOS 6

 Helvetica Helvetica

iOS 7

.Helvetica Neue Interface .HelveticaNeueInterface-M3

但您可以只使用 Helvetica Neue

You can always use

UIFont *systemFont = [UIFont systemFontOfSize:12];
NSLog(@"what is it? %@ %@", systemFont.familyName, systemFont.fontName);

The answer is:

Up to iOS 6

 Helvetica Helvetica

iOS 7

.Helvetica Neue Interface .HelveticaNeueInterface-M3

but you can just use Helvetica Neue

说不完的你爱 2024-10-02 20:28:35

我不确定是否有一个 api 可以获取默认的系统字体名称。所以我就得到了这样的名字:

    //get system default font
    UILabel *label = [[UILabel alloc] init];        
    fontname = label.font.fontName;
    [label release];

看起来很愚蠢,但它确实有效。

I'm not sure there is an api to get the default system font name. So I just get the name like this :

    //get system default font
    UILabel *label = [[UILabel alloc] init];        
    fontname = label.font.fontName;
    [label release];

Looks stupid but it works.

冷了相思 2024-10-02 20:28:35

以下是支持 iOS 7 的一些更新。它有 动态字体大小现在。

对于所有支持“动态类型”的应用程序,用户可以选择
iOS 7 中适用于系统范围的字体大小,只需访问
“设置”下的“常规”部分并选择“字体大小”。

UIFont *dynamicFont  = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];

和常量列表,详细解释为此处

NSString *const UIFontTextStyleHeadline;
NSString *const UIFontTextStyleSubheadline;
NSString *const UIFontTextStyleBody;
NSString *const UIFontTextStyleFootnote;
NSString *const UIFontTextStyleCaption1;
NSString *const UIFontTextStyleCaption2;

Here is some update for supporting iOS 7. It has Dynamic Font Size now.

For any and all apps that support “Dynamic Type,” users can select a
font size in iOS 7 that works system wide, simply by visiting the
"General" section under "Settings" and selecting "Font Size."

UIFont *dynamicFont  = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];

And constants list, detailed explanation is here

NSString *const UIFontTextStyleHeadline;
NSString *const UIFontTextStyleSubheadline;
NSString *const UIFontTextStyleBody;
NSString *const UIFontTextStyleFootnote;
NSString *const UIFontTextStyleCaption1;
NSString *const UIFontTextStyleCaption2;
瞄了个咪的 2024-10-02 20:28:35

UIFont (UIInterface.h) 的类别 UIFontSystemFonts 提供了几种方便的预定义尺寸。

@interface UIFont (UIFontSystemFonts)
 + (CGFloat)labelFontSize;
 + (CGFloat)buttonFontSize;
 + (CGFloat)smallSystemFontSize;
 + (CGFloat)systemFontSize;
@end 

我将它用于聊天消息(标签),当我需要获取文本块的大小时它效果很好。

 [UIFont systemFontOfSize:[UIFont labelFontSize]];

快乐编码!

Category UIFontSystemFonts for UIFont (UIInterface.h) provides several convenient predefined sizes.

@interface UIFont (UIFontSystemFonts)
 + (CGFloat)labelFontSize;
 + (CGFloat)buttonFontSize;
 + (CGFloat)smallSystemFontSize;
 + (CGFloat)systemFontSize;
@end 

I use it for chat messages (labels) and it work well when I need to get size of text blocks.

 [UIFont systemFontOfSize:[UIFont labelFontSize]];

Happy coding!

没有伤那来痛 2024-10-02 20:28:35
UIFont *systemFont = [UIFont systemFontOfSize:[UIFont systemFontSize]];

这将为您提供系统字体,并且默认情况下应用于标签文本的默认系统字体大小。

UIFont *systemFont = [UIFont systemFontOfSize:[UIFont systemFontSize]];

This will give you the system font with the default system font size applied for the label texts by default.

你对谁都笑 2024-10-02 20:28:35

Swift

您应该始终使用系统默认值,而不是对字体名称进行硬编码,因为 Apple 可能随时更改默认字体。

有几种不同大小(标签、按钮等)的系统默认字体(正常、粗体斜体):

let font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
let font2 = UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)
let font3 = UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)

请注意,默认字体大小取决于目标视图(标签、按钮、其他)

示例:

let labelFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
let buttonFont = UIFont.systemFont(ofSize: UIFont.buttonFontSize)
let textFieldFont = UIFont.systemFont(ofSize: UIFont.systemFontSize)

Swift

You should always use the system defaults and not hard coding the font name because the default font could be changed by Apple at any time.

There are a couple of system default fonts(normal, bold, italic) with different sizes(label, button, others):

let font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
let font2 = UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)
let font3 = UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)

beaware that the default font size depends on the target view (label, button, others)

Examples:

let labelFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
let buttonFont = UIFont.systemFont(ofSize: UIFont.buttonFontSize)
let textFieldFont = UIFont.systemFont(ofSize: UIFont.systemFontSize)
反差帅 2024-10-02 20:28:35
  1. 下载所需的.ttf文件

  2. 将.ttf文件添加到复制捆绑资源下,仔细检查是否
    在资源下添加 ttf 文件

  3. 在 info.pllist 中按原样添加 ttf 文件名。

  4. 现在打开字体簿,将.ttf文件添加到字体簿中,选择
    信息图标,您可以在其中找到 postscript 名称。

  5. 现在在字体名称的位置给出后记名称

  1. download required .ttf file

  2. add the .ttf file under copy bundle resource, double check whether
    the ttf file is added under resource

  3. In info.pllist add the ttf file name as it is.

  4. now open the font book add the .ttf file in the font book, select
    information icon there you find the postscript name.

  5. now give the postscript name in the place of font name

掩于岁月 2024-10-02 20:28:35

iOS 的默认字体是 San Francisco 。您可以参考链接了解更多信息细节

The default font for iOS is San Francisco . You can refer the link for further details

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文