• 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
Re: scale text proportionally as bounds increase
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scale text proportionally as bounds increase


  • Subject: Re: scale text proportionally as bounds increase
  • From: sqwarqDev <email@hidden>
  • Date: Sun, 01 Mar 2015 13:05:27 +0700

> On 24 Feb 2015, at 05:08, Jens Alfke <email@hidden> wrote:
>
>> On Feb 23, 2015, at 8:49 AM, sqwarqDev <email@hidden> wrote:
>>
>> How do I programmatically tell each NSControl to increase its text size proportionally as its bounds increase?
>
> You’ll have to do it manually. Observe the control’s frame, then when it changes compute a new font size and update the control’s font.
>
> (The easy way is to assume that text width scales linearly with font size; strictly speaking this isn’t always true, but it’s probably true of any standard system font like Helvetica that you’d be displaying in a control.)
>


Thanks all. There's a fairly in-depth discussion covering many of the more complex scenarios here:

http://www.cocoabuilder.com/archive/cocoa/303445-linearly-scaling-text.html

However, my needs were fairly simple, and I was able to effect a satisfactory solution with the following:

- (void)windowDidResize:(NSNotification *)notification {

    float a = 110;
    NSSize myNSWindowSize = [[window contentView ] frame ].size;

    if (myNSWindowSize.height > 220) {
        if (myNSWindowSize.width > myNSWindowSize.height) {
            a = myNSWindowSize.height/2.4;
        } else {
            a = myNSWindowSize.width/3.8;
        }
    }

    NSFont *f = [NSFont fontWithName:@"Helvetica Neue" size:a];
    [textField setFont:f];

}



Best

Phil

DisplayDroid beta (a lightweight script editor and automation tool) is now available for free download. More info on sqwarq.com/displaydroid
OSXClock - big, beautiful alarm clock and timer for your mac. More info on sqwarq.com/osxclock

http://applehelpwriter.com
http://sqwarq.com - apps for OS X & iOS











_______________________________________________

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


References: 
 >scale text proportionally as bounds increase (From: sqwarqDev <email@hidden>)
 >Re: scale text proportionally as bounds increase (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Programmatically change screen saver settings
  • Previous by thread: Re: scale text proportionally as bounds increase
  • Next by thread: What's wrong with this code, why is the label invisible?
  • Index(es):
    • Date
    • Thread