tags:

views:

25

answers:

2

Hi, 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

+2  A: 

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:

  if ([[UIDevice currentDevice] systemVersion] >= @"3.2") {
    return @"myExternalFontName";
} else {
    return @"AppleGothic";
}

Or does anyone has a better solution? Thanks

Eva Madrazo
Good idea. :) (SO has got a STUPID character limit..)
Emil
+1  A: 

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.

Brad Larson
good idea, thank you!
Eva Madrazo