Search code examples
iosuitextfielduicoloruifontdrawinrect

Font problems on retina display


I'm kind of newbie in Objective-C and I need some help My problem is that I have a subclass of UITextField, and I want to set the placeholder font to be custom with this code

- (void)drawPlaceholderInRect:(CGRect)rect {
[[self placeholder] drawInRect:rect withAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"Georgia Belle" size:25],NSForegroundColorAttributeName:RGBA(174, 150, 108, 1)}]; } 

and I have the next issue. When I select iPad in the simulator, and I compile the program, everything goes as it should, but when I select a retina device I get the next Exception:

 [__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0].

What I'm asking is: why it works on non-retina but throws exceptions on retina, any kind of retina device.


Solution

  • Your problem is with your Font.

    HelveticaNeueInterface-Regular is the System font. Like: [UIFont systemFontOfSize:25]

    In the other hand I can't use RGBA(174, 150, 108, 1) I've got an issue in my code.

    You should be sure that you have the font named "Georgia Belle" is in your project well imported.

    Drag and drop Georgia Belle.ttf to your project

    enter image description here

    Open Info.plist and add a new line:

    enter image description here

    Open your Target / Build Phases / Copy Bundle Resources
    Xcode fails here and sometimes its not adding our new font:

    enter image description here

    Click +

    enter image description here

    Done

    enter image description here

    Problem solved.

    enter image description here enter image description here

    You can download my solution from GitHub

    One last thing. This is a nice website with all the standard ios fonts: http://iosfonts.com