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

  • Home
  • SEARCH
  • 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 7833361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:40:32+00:00 2026-06-02T12:40:32+00:00

I am trying to allow iPhone app users to personalize an application by setting

  • 0

I am trying to allow iPhone app users to personalize an application by setting custom fonts. I am wondering if I can save an UIFont Object to the NSUserDefaults. Would make things a lot easier to set the font and font size and then save the object. Code sample would be great too.

  • 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-02T12:40:33+00:00Added an answer on June 2, 2026 at 12:40 pm

    I would make a category to hide the complexity – you might start with something like this

    .h

    // NSUserDefaults+CustomFontAdditions.h
    
    @interface NSUserDefaults (CustomFontAdditions)
    
    - (UIFont *)ps_fontForKey:(NSString *)fontKey;
    - (void)ps_setFont:(UIFont *)font forKey:(NSString *)fontKey;
    
    @end
    

    .m

    // NSUserDefaults+CustomFontAdditions.m
    
    #import "NSUserDefaults+CustomFontAdditions.h"
    
    NSString * const PSCustomFontsKey        = @"PSCustomFontsKey";
    NSString * const PSCustomFontKeyFontName = @"PSCustomFontKeyFontName";
    NSString * const PSCustomFontKeyFontSize = @"PSCustomFontKeyFontSize";
    
    @implementation NSUserDefaults (CustomFontAdditions)
    
    - (UIFont *)ps_fontForKey:(NSString *)fontKey;
    {
        NSDictionary *fonts = [self dictionaryForKey:PSCustomFontsKey];
    
        UIFont *font = nil;
    
        if (fonts) {
            NSDictionary *fontComponents = [fonts valueForKey:fontKey];
    
            NSString *fontName = [fontComponents valueForKey:PSCustomFontKeyFontName];
            CGFloat   size     = [[fontComponents valueForKey:PSCustomFontKeyFontSize] floatValue];
    
            font = [UIFont fontWithName:fontName size:size];
        }
    
        return font;
    }
    
    - (void)ps_setFont:(UIFont *)font forKey:(NSString *)fontKey;
    {
        NSMutableDictionary *fonts = [[self dictionaryForKey:PSCustomFontsKey] mutableCopy];
    
        if (!fonts) {
            fonts = [[NSMutableDictionary alloc] initWithCapacity:1];
        }
    
        NSDictionary *fontComponents = [[NSDictionary alloc] initWithObjectsAndKeys:
                                        font.fontName, PSCustomFontKeyFontName,
                                        [NSNumber numberWithFloat:font.pointSize], PSCustomFontKeyFontSize, nil];
    
        [fonts setValue:fontComponents forKey:fontKey];
    
        [self setObject:fonts forKey:PSCustomFontsKey];
    }
    
    @end
    

    Usage would look like

    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
    [standardUserDefaults ps_setFont:[UIFont systemFontOfSize:12.0f] forKey:@"font1"];
    [standardUserDefaults ps_setFont:[UIFont fontWithName:@"Helvetica Neue" size:24.0f] forKey:@"font2"];
    [standardUserDefaults synchronize];
    
    NSLog(@"%@", [standardUserDefaults ps_fontForKey:@"font1"]);
    NSLog(@"%@", [standardUserDefaults ps_fontForKey:@"font2"]);
    

    Outputs:

    #=> 2012-04-19 00:01:21.756 ma[1340:f803] <UICFFont: 0x68a18b0> font-family: "Helvetica"; font-weight: normal; font-style: normal; font-size: 12px
    #=> 2012-04-19 00:01:21.765 ma[1340:f803] <UICFFont: 0x6b99670> font-family: "Helvetica Neue"; font-weight: normal; font-style: normal; font-size: 24px
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my iPhone app, I'm trying to allow users to post an audio track
Background: I am trying to create a really simple iPhone app that will allow
Hi fellow Stackoverflow users, I am trying to optimize my iphone application startup time
I am trying to have the functionality where I can allow the users to
Can’t install application The application at /Users/myname/Documents/SDK/iPhoneApplications/x/build/Debug-iphoneos/x.app does not specify a CFBundleExecutable I don't
Im trying to allow users to login to a website by verifying if they
I'm trying to allow users to post videos on my site by supplying only
Im trying to look into using the WPF WriteableBitmap class to allow my application
I have an iPhone app that will let users email some pre-determined text as
we can easily capture a view(screenshot) programmatically in iPhone. But i am trying to

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.