ios iPhone系统字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3838336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:49:49  来源:igfitidea点击:

iPhone system font

iosiphonefontstypeface

提问by SK9

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

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

I would like to retrieve this for customizing a UIView.

我想检索它以自定义UIView.

回答by Gary Willoughby

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.

令各地字体纯粹主义者高兴的是,iPhone 系统界面使用 Helvetica 或其变体。

最初的 iPhone、iPhone 3G 和 iPhone 3GS 系统界面使用 Helvetica。正如一向出色的 DaringFireball 首次指出的那样,iPhone 4 使用了一种经过巧妙修改的字体,称为“Helvetica Neue”。DaringFireball 还指出,这一变化与 iPhone 4 显示屏有关,而不是与 iOS 4 操作系统有关,运行 iOS 4 的旧 iPhone 机型仍然使用 Helvetica 作为系统字体。

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

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

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

For iOS9it has changed to San Fransisco. See http://developer.apple.com/fontsfor more info.

对于iOS9,它已更改为San Fransisco。有关更多信息,请参阅http://developer.apple.com/fonts

回答by Adam Wright

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

如果您正在进行程序化定制,请不要对系统字体进行硬编码。使用UIFont systemFontOfSize:,UIFont boldSystemFontOfSize:UIFont italicSystemFontOfSizeApple 文档)。

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

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

This has become superespecially relevant since iOS 9, which changed the system font againto San Francisco.

这已经成为超级以来的iOS 9,它改变了系统字体特别是有关再次到旧金山。

回答by Vladimir

afaik iPhone uses "Helvetica" by default < iOS 10

afaik iPhone默认使用“ Helvetica” < iOS 10

回答by Suragch

Swift

迅速

Specific font

特定字体

Setting a specific font in Swift is done like this:

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

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.

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

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 Stylewe are working with. This is the recommended way of setting the font. See Supporting Dynamic Typefor more info on this.

啊,现在我们有了用户为我们正在使用的文本样式选择的大小的系统字体。这是设置字体的推荐方式。有关更多信息,请参阅支持动态类型

Related

有关的

回答by Dan Rosenstark

You can always use

您可以随时使用

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

The answer is:

答案是:

Up to iOS 6

至 iOS 6

 Helvetica Helvetica

iOS 7

IOS 7

.Helvetica Neue Interface .HelveticaNeueInterface-M3

but you can just use Helvetica Neue

但你可以使用 Helvetica Neue

回答by perkin tang

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

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

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

Looks stupid but it works.

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

回答by B.S.

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

下面是一些更新支持iOS的7。现在有了Dynamic Font Size

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."

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

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;

回答by Anton Gaenko

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

分类UIFontSystemFontsUIFontUIInterface.h)提供了一些便利的预定义的大小。

@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!

快乐编码!

回答by Rohit saraf

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.

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

回答by Musa almatri

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.

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

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)