更改 iPhone 应用程序的系统字体 - 整个应用程序
有没有办法可以更改整个应用程序的系统字体?
我想为整个应用程序定义字体,这样我就不必去单独的标签或单独的字体来更改它。我想要一个通用定义,它将更改应用程序中存在的所有字体。我该怎么做?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用 Pixate 来设计您的应用程序。
使用 pixate 时,您可以通过 CSS 设置 UI 元素的样式属性。
这样您就可以全局设置您的 UILabels 和 UITextField 等以使用您的自定义字体。
这是迄今为止全局设置字体样式的最佳方式。
在我的应用程序中,我必须使用“Open Sans”并设置所有 UILabels、UITextFields 和 UITextViews 来使用该字体:
在“default.css”中
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"
创建一个名为
Constants.h
或其他名称的共享类。在其中执行以下操作:当然,将字体调整为您需要的字体。然后,每当您需要使用它(在标签或其他任何地方)时,请执行以下操作:
Make a shared class called
Constants.h
or something. In it do this: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:
我认为正确的答案是:不要这样做!弄清楚为什么你认为你想要这样做,然后找出其他方法来达到相同的目的。这里的人们很乐意帮助找出实现这些目标的另一种方法。 (例如,这就是 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?
似乎至少对
UILabel
有效:Seems to work at least for
UILabel
s:不 - 这就是为什么它被称为系统字体,而不是应用程序字体。
No - that's why it's called the system font, and not the application font.
字体特定于 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.