Changing button size programmatically

  • Hi,I've been trying to create a subclass of NSButton that can have its size changed during runtime.

    I'm using a round button (NSCircularBezelStyle), and I need to be able to set the exact radius of the button, which is different for each instance of the button. There doesn't seem to be any way of doing this in either the NSButton class or NSButtonCell class.

    I've tried creating my own buttons from scratch using subclasses of NSView, NSImageView and NSCell, but all of these seemed to have their own problems (in NSCell, for instance, when you change the image size (using NSImage's setSize: method) it just seems to change how much of the image is shown; in NSImageView I couldn't work out how to display the button's title; and in NSView my programming is simply not good enough to create a button that looks good).

    Can anyone help?

    Thanks in advance if you can,

    Simon Jones

    _______________________________________________
    Join Excite! - http://www.excite.com
    The most personalized portal on the Web!
  • Simon,

    Try making a category of NSButton, add a method like this:

    - (void)setBoundsRadius:(float)radius
    {
      NSRect rect = [self bounds];

      rect.size.width = radius * 2;
      rect.size.height = radius * 2;

      [self setBounds: rect];
    }

    Peace, Alan

    --
    My blog: cocoalatte.info

    // Things I've said -------------------------
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
    "When the World realizes that personal beliefs are not something to
    argue or fight over, it shall evolve."
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today