在 iphone 4 中使用特定字体,但在 3.2 版本之前不使用
我正在为我的应用程序使用外部字体功能。 由于 3.1 版本不支持外部字体,我想定义与正在执行程序的 IOS 相关的字体名称。我在 Constants.h 文件中定义了 MY_FONT_NAME 变量,如下所示:
//#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
#ifdef __IPHONE_3_2
#define MY_FONT_NAME @"ExternalFontName"
#else
#define MY_FONT_NAME @"AppleGothic"
#endif
我尝试了第一行和第二行,但没有成功,但它总是获得“externalFontName”的值,甚至在 3.1 设备上执行...并且所以,当我在标签中设置字体时,出现错误
'NSInternalInconsistencyException',原因:'无效参数不满足:font != nil'
有人知道问题是什么吗?提前致谢
I am using the external fonts capability for my application.
As external fonts are not supported in 3.1 version I would like to define the font name in relation with the IOS that is executing the program. I have defined MY_FONT_NAME variable in a Constants.h file like this:
//#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
#ifdef __IPHONE_3_2
#define MY_FONT_NAME @"ExternalFontName"
#else
#define MY_FONT_NAME @"AppleGothic"
#endif
I have tried both, the first commented line and the second, without success but it always get the value of "externalFontName", even executing on a 3.1 device... and so, when I set the font in a label I get the error
'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: font != nil'
Anyone know what is the problem?? Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我知道,宏是在编译时执行的,这就是问题所在..太愚蠢了!抱歉:)
所以我想我应该使用类似的东西:
或者有人有更好的解决方案吗?谢谢
ok, I know, the macros are executed on compilation time, that is the problem.. so stupid! sorry :)
So I think I should use something like:
Or does anyone has a better solution? Thanks
也许更好的方法是使用 UIFont 的
+fontWithName:size:
来检查字体的可用性,和/或检查从+familyNames
返回的数组和+fontNamesForFamilyName:
。例如,我相信有些字体仅出现在运行 3.2 的 iPad 上,甚至与运行 4.0 的 iPhone 相比也是如此。
Perhaps a better approach would be to use UIFont's
+fontWithName:size:
to check the availability of the font, and / or examining the returned arrays from+familyNames
and+fontNamesForFamilyName:
.For example, I believe there are some fonts that are only present on the iPad running 3.2, even versus an iPhone running 4.0.
伊娃·马德拉索(Eva Madrazo)很接近。您真正需要的是:
因为字符串比较不会削减它。
Eva Madrazo is close. What you actually need is:
because a string compare doesn't cut it.