0

I am getting this exception on setting a font of UILabel in iOS 3.1.2 but its running fine in iOS 4,

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: font != nil'

The code line is,

Outbound_Label.font = [UIFont fontWithName:@"DS-Digital" size:24];

where DS-Digital is my custom font.

  • 1
    maybe you should check return value, seems it doesn't find your font. better check whether resource file is properly included. – AndersK Sep 28 '11 at 10:43

3 Answers3

1

My guess is that your custom font is not being found instantiated.

Whenever I have a problem like this where there are two things happening: obtaining a font and setting a font, I separate them to find the problem:

UIFont *font = [UIFont fontWithName:@"DS-Digital" size:24];
Outbound_Label.font = font;

Then I can determine where the error is easily with either the debugger or NSLog().

In fact this is a very clear way to write the code in the first place. I never worry about optimization, I only worry about clarity and ease of maintenance. Later if there are performance issues I profile, find the real culprits and resolve them. The clearer the code the easier that is.

In a case like this the compiler will undoubtedly optimize away the font variable so there is no harm.

See this:SO answer
Applications that want to use custom fonts can now include those fonts in their application bundle and register those fonts with the system by including the UIAppFonts key in their Info.plist file. The value of this key is an array of strings identifying the font files in the application’s bundle. When the system sees the key, it loads the specified fonts and makes them available to the application.

Community
  • 1
  • 1
zaph
  • 111,848
  • 21
  • 189
  • 228
  • i have tried using the above method, but it crashes on second line. – Mobile Developer iOS Android Sep 28 '11 at 11:04
  • On the first line, is done nil or a font instance? If done is good, Outbound_Label valid? BTW, what is Outbound_Label? the coding practice is to make variables camel case beginning with a lower case letter, classes begin with an upper case letter. That makes understanding code easier and ARC requires that convention. – zaph Sep 28 '11 at 11:10
  • font is nil in first code line, and also Outbound_Label is a UIalbel. Can you tell me what are possible reasons for that nil value, as i already have DS-DIGI.ttf added in resources. – Mobile Developer iOS Android Sep 28 '11 at 11:42
1

[UIFont fontWithName:@"DS-Digital" size:24] returns nil. Because no font available for "DS-Digital" (Apple supported font list). so it giving the crash.

Ishu
  • 12,797
  • 5
  • 35
  • 51
0

Please try this, it's works fine for me.

https://github.com/zynga/FontLabel

i have download DS-Digital font from http://www.fontriver.com/font/ds-digital/ and run the above app with this font and it's works with IOS 3.1.2.

Cheers.

AppsDev
  • 85
  • 5