Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8372631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:28:55+00:00 2026-06-09T14:28:55+00:00

My Mac OS application draws some text using code like this: void drawString(NSString* stringToDraw)

  • 0

My Mac OS application draws some text using code like this:

void drawString(NSString* stringToDraw)
{
    NSFontManager *fontManager = [NSFontManager sharedFontManager];
    NSString* fontName =  [NSString stringWithCString: "Helvetica" encoding: NSMacOSRomanStringEncoding];
    NSFont* font = [fontManager fontWithFamily:fontName traits:0 weight:5 size:9];
    NSMutableDictionary *attribs = [[NSMutableDictionary alloc] init];
    [attribs setObject:font forKey:NSFontAttributeName];
    [stringToDraw drawAtPoint:NSMakePoint (0, 0) withAttributes:attribs];
}

Since text drawing is very small part of the application this simple approach has worked well so far. But now with the new retina display, users complain that the text appears too big compare to the rest of the graphics. It seems that giving an absolute font size (9 in my case) no longer works.

How can I fix this code so that it works well for both retina and non-retina displays?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:28:57+00:00Added an answer on June 9, 2026 at 2:28 pm

    Font size is measured in points, not in pixels. So any value should be independent of Retina resolution. For example, this code works okay:

    - (void)drawRect:(NSRect)dirtyRect
    {
        CGRect textRect = CGRectInset(self.bounds, 15.0, 15.0);
    
        [[[NSColor whiteColor] colorWithAlphaComponent:0.5] setFill];
        NSRectFillUsingOperation(textRect, NSCompositeSourceOver);
    
        NSFont *font = [[NSFontManager sharedFontManager] fontWithFamily:@"Helvetica"
                                                                  traits:0.0
                                                                  weight:5.0
                                                                    size:30.0];
        [@"Hello\nWorld" drawInRect:textRect
                     withAttributes:@{ NSFontAttributeName : font }];
    }
    

    Results:

    Non-retina

    Retina

    If you have precise pixel sizes for different display modes, try something like this:

    CGFloat contentsScale = self.window.backingScaleFactor;
    CGFloat fontSize = (contentsScale > 1.0 ? RETINA_FONT_SIZE : STANDARD_FONT_SIZE);
    NSFont *font = [[NSFontManager sharedFontManager] fontWithFamily:@"Helvetica"
                                                              traits:0.0
                                                              weight:5.0
                                                                size:fontSize];
    

    Does it work?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application (for Mac) generates some HTML... This HTML then needs to be saved
I am working in a mac application with snowleopard.This application is created with leopard
I'm basically trying to extract a Mac application from a zip file using QuaZip.
So I am writing a mac application that parses SF Giants baseball statistics using
I have this Mac application that consists of 2 files: firstFile.tst secondFile I would
I am developing Mac desktop application, where I am capturing the screen using CGImageRef
I am developing a MAC application wherein I have to decode few images using
I was looking at an open source Mac application, and they gave some suggested
In my Mac application I'd like to implement a view that simulates UITabBar from
This page explains how to make a Mac application to handle custom URL schemes.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.