Re: Change text size in NSTables
Re: Change text size in NSTables
- Subject: Re: Change text size in NSTables
- From: Jonathan <email@hidden>
- Date: Fri, 07 Apr 2006 09:47:06 -0700
- Thread-topic: Change text size in NSTables
Hi, Sanjay--
Thank you for the help.
I guess as this was my first day in Cocoa, this is all a bit overwhelming.
May I ask if this can be assigned to whatever is being used as the system
font? I assume that¹s what the default font for NSTable is in any case. So
must I specify that, and if so, how?
Jonathan
on 4/7/06 9:05 AM, Sanjay Samani at email@hidden wrote:
> Woops, actually if you're doing it programmatically and not using the Font
> Panel you could also use:
>
> -[[NSFontManager sharedFontManager] convertFont: toSize:]
>
> Also I got it wrong with defaultManager below, it should be
> sharedFontManager. See the following link for more manual font conversion:
>
> file:/Developer/ADC Reference Library/documentation/Cocoa/Conceptual/FontH
> andling/Tasks/ConvertingFontsManually.html
> <file:///Developer/ADC Reference Library/documentation/Cocoa/Conceptual/Fo
> ntHandling/Tasks/ConvertingFontsManually.html>
>
> Sanjay
>
> On 7 Apr 2006, at 16:40, Sanjay Samani wrote:
>
>>
>> Jonathan,
>>
>> I think you need to add a -changeFont: method to your window controller, as
>> described here
>>
>> file:///Developer/ADC Reference Library/documentation/Cocoa/Conceptual/Fo
>> ntHandling/Tasks/RespondingToFontChanges.html
>>
>> Basically the Font panel will send this message to the window controller. in
>> your -setSelectedFont method you then update the cells for each column in
>> your table view using the new Font.
>>
>> If you are not using the font panel and are instead doing this
>> programmatically, then using NSFont's +fontWithName:size: gets the
>> appropriate font, which you can then pass to your setSelectedFont: method (or
>> use wherever you want). You can adjust the font traits of an
>> NSAttributedString but not of an NSFont. I think the idea is that fonts are
>> cached by the system, so you just keep asking for whatever one you want.
>> So to use a different font for a table, you just get the appropriate font
>> from the NSFont +fontWithName:size: and set the table view data cell
>> accordingly and adjust the row size accordingly.
>>
>> I had an app I wrote 4 years ago that did this, so its a bit vague, but I
>> seem to have copied and pasted the code out of the link above and it worked
>> fine when using the Font Panel. Basically what I've got in my window
>> controller class is:
>>
>> - (void)changeFont:(id)sender {
>> NSFont *oldFont = [[[myTableView tableColumnWithIdentifier:@"columnId"]
>> dataCell] font];
>> NSFont *newFont = [sender convertFont:oldFont];
>>
>> [self setSelectedFont:newFont];
>> }
>>
>> // Set Fonts for Table View
>> - (void) setSelectedFont:(NSFont *)font {
>>
>> [[[myTableView tableColumnWithIdentifier:@"columnId"] dataCell]
>> setFont:font];
>>
>> }
>>
>> The sender in changeFont is the [NSFontManager defaultManager]
>>
>> The reason I had setSelectedFont separately is that I stored the last
>> selected font in the user defaults and set it for all my table view on
>> application startup.
>>
>> Sanjay
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden