• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Font binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Font binding


  • Subject: Font binding
  • From: Andre Masse <email@hidden>
  • Date: Sat, 29 Nov 2008 13:34:24 -0500

Hi all,

I want some fonts in my views to be customizable. Notably, for a table view. I added a font in the user defaults and this part works fine. I did some test on a label and it doesn't work.

I want to change the label's font and display the font name. Here's what I've done:

I placed 3 buttons (show font, save font and test font) and a label in a view and bound the Font (in IB) like this:

Controller key: "values", Model Key Path: "userFonts.smallFontForList", Value Transformer: "NSKeyedUnarchiveFromData"

Here's the code:


- (IBAction)showFontPanel:(id)sender { NSFontPanel *fontPanel = [NSFontPanel sharedFontPanel]; [fontPanel orderFront:sender]; }

-(IBAction)saveFont:(id)sender
{
//get the saved font
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *fontDict = [NSMutableDictionary dictionaryWithDictionary:[userDefault objectForKey:@"userFonts"]];
NSData *oldFontAsData = [fontDict objectForKey:@"smallFontForList"];
NSFont *oldFont = [NSKeyedUnarchiver unarchiveObjectWithData:oldFontAsData];

//change it
NSFontPanel *fontPanel = [NSFontPanel sharedFontPanel];
NSFont *newFont = [fontPanel panelConvertFont:oldFont];

//save it
NSData *newFontAsData = [NSKeyedArchiver archivedDataWithRootObject:newFont];

[fontDict setObject:newFontAsData forKey:@"smallFontForList"];
[userDefault setObject:fontDict forKey:@"userFonts"];


}


- (IBAction)testFont:(id)sender
{
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *fontDict = [userDefault objectForKey:@"userFonts"];


	NSData *data = [fontDict objectForKey:@"smallFontForList"];
	NSFont *tf = [NSKeyedUnarchiver unarchiveObjectWithData:data];
	[test setStringValue:[tf fontName]];
}

The label changes its value but not its font. Must be some silly thing I overlook...

Any hints?

Thanks,

Andre Masse



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Keystrokes for non-ascii letters
  • Next by Date: Re: Checking One Array Against Another
  • Previous by thread: Re: QuartzCore and CIContext
  • Next by thread: reading a PDF
  • Index(es):
    • Date
    • Thread