1

How could I subclass a NSBox to change the width, height , font type and background color of the Box's title?.

一二三
  • 21,059
  • 11
  • 65
  • 74
Javier Beltrán
  • 756
  • 5
  • 26
  • `NSBox` is an `NSView` subclass, so you can subclass in and override `drawRect:` to do whatever you like. What have you tried? – jscs May 03 '11 at 21:37

1 Answers1

1

Most of those look like they can be set with simple calls to NSBox's accessors, and the size and background color can be set by calling [myBox title] then calling the appropriate methods on the returned NSCell.

So subclassing NSBox to do all of these things would be as simple as setting the right properties in -init, and making sure to override the methods listed in the "Subclassing Notes" section within NSBox's Class Reference.

matthias
  • 2,419
  • 1
  • 18
  • 27
  • could you help me with a example of how i could change the titlerect? – Javier Beltrán May 04 '11 at 19:17
  • It's a plain C struct, so you should be able to do the following: NSRect myRect = [myNSBox titleRect]; myRect.size.width = (CGFloat) whateverWidth; myRect.size.height = (CGFloat) whateverHeight; – matthias May 06 '11 at 02:04