更改 iPhone 应用程序的系统字体 - 整个应用程序

发布于 2024-08-11 03:43:54 字数 107 浏览 1 评论 0原文

有没有办法可以更改整个应用程序的系统字体?

我想为整个应用程序定义字体,这样我就不必去单独的标签或单独的字体来更改它。我想要一个通用定义,它将更改应用程序中存在的所有字体。我该怎么做?

Is there a way I can change the System Font for an entire Application?

I want to define the font for the entire Application so that I don't have to go to individual labels or individual fonts to change it. I would like a universal definition which will change all the fonts that exist within the application. How do I do this?

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

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

发布评论

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

评论(6

深空失忆 2024-08-18 03:43:54

您可以使用 Pixate 来设计您的应用程序。
使用 pixate 时,您可以通过 CSS 设置 UI 元素的样式属性。
这样您就可以全局设置您的 UILabels 和 UITextField 等以使用您的自定义字体。
这是迄今为止全局设置字体样式的最佳方式。

在我的应用程序中,我必须使用“Open Sans”并设置所有 UILabels、UITextFields 和 UITextViews 来使用该字体:

在“default.css”中

label {
    font-family: "Open Sans";
}

text-field {
    font-family: "Open Sans";
}

text-view {
    font-family: "Open Sans";
}

在此处输入图像描述

You can use Pixate to style your app.
When using pixate, you can set the style attributes of your UI elements via CSS.
This way you can globally setup your UILabels and UITextField etc. to use your custom font.
This is by far the best way to globally style your font.

In my app I had to use "Open Sans" and setup all my UILabels, UITextFields and UITextViews to use that font:

In your "default.css"

label {
    font-family: "Open Sans";
}

text-field {
    font-family: "Open Sans";
}

text-view {
    font-family: "Open Sans";
}

enter image description here

叹梦 2024-08-18 03:43:54

创建一个名为 Constants.h 或其他名称的共享类。在其中执行以下操作:

#define kStandardFont [UIFont systemFontOfSize:20] 

当然,将字体调整为您需要的字体。然后,每当您需要使用它(在标签或其他任何地方)时,请执行以下操作:

#import "Constants.h"
…
…
… 
[label setFont:kStandardFont];

Make a shared class called Constants.h or something. In it do this:

#define kStandardFont [UIFont systemFontOfSize:20] 

Of course adjust the font to be what you need it to be. Then, whenever you need to use it (in a label or whatever) do this:

#import "Constants.h"
…
…
… 
[label setFont:kStandardFont];
眼眸 2024-08-18 03:43:54

我认为正确的答案是:不要这样做!弄清楚为什么你认为你想要这样做,然后找出其他方法来达到相同的目的。这里的人们很乐意帮助找出实现这些目标的另一种方法。 (例如,这就是 coneybeare 的答案所有效建议的。)

话虽如此……官方 SDK 中没有办法更改系统字体。您也许可以通过调整 UIFont 的 systemFontWithSize: 方法来取得一些进展 - 请参阅 http://www .cocoadev.com/index.pl?MethodSwizzling 了解有关方法调配的更多信息。请记住,(a) 这只会改变使用 systemFontWithSize: 获取其字体的任何内容的外观,(b) 这可能会破坏依赖于原始字体大小的所有内容,(c) 这很可能让你被 App Store 拒绝。

所有这些警告加起来就产生了一个问题:你真正想用这个来实现什么目的?

I think that the right answer is: Don't do that! Figure out why you think you want to do that, and then figure out some other way to achieve the same ends. And folks here would be happy to help figure out another way to those ends. (E.g. that's what coneybeare's answer effectively suggests.)

All that said...there's no way in the official SDK to change the system font. You might be able to make some headway by swizzling UIFont's systemFontWithSize: method -- see http://www.cocoadev.com/index.pl?MethodSwizzling for more on method swizzling. Bear in mind (a) this will only change the appearance of anything that uses systemFontWithSize: to get its font, (b) this might break all kinds of things that depend on the having the original font size, and (c) this might well get you rejected from the App Store.

All these caveats add up to the question: What are you really trying to accomplish with this?

下壹個目標 2024-08-18 03:43:54

似乎至少对 UILabel 有效:

@interface UIFont (mxcl)
@end
@implementation UIFont (mxcl)
+ (id)systemFontOfSize:(CGFloat)sz {
    return [UIFont fontWithName:@"AmericanTypewriter" size:sz]
}
+ (id)boldSystemFontOfSize:(CGFloat)sz {
    return [UIFont fontWithName:@"AmericanTypewriter-Bold" size:x]
}
@end

Seems to work at least for UILabels:

@interface UIFont (mxcl)
@end
@implementation UIFont (mxcl)
+ (id)systemFontOfSize:(CGFloat)sz {
    return [UIFont fontWithName:@"AmericanTypewriter" size:sz]
}
+ (id)boldSystemFontOfSize:(CGFloat)sz {
    return [UIFont fontWithName:@"AmericanTypewriter-Bold" size:x]
}
@end
山人契 2024-08-18 03:43:54

不 - 这就是为什么它被称为系统字体,而不是应用程序字体。

No - that's why it's called the system font, and not the application font.

小…红帽 2024-08-18 03:43:54

字体特定于 UI 中的每个控件。例如,每个 UILabel 都有自己的字体设置。

如果您想更改所有控件的字体,则必须全部更改。

Fonts are specific to each control in the UI. For exmaple, each UILabel has its own font setting.

If you want to change the font of all controls, you'll have to change them all.

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