Changing the Cell for a Control
Because NSControl uses objects derived from the NSCell class to implement most of its functionality, you can usually implement a unique user interface device by creating a subclass of NSCell rather than NSControl. As an example, let’s say you want all your application’s NSSliders to have a type of cell other than the generic NSSliderCell. First, you create a subclass of NSCell, NSActionCell, or NSSliderCell. (Let’s call it MyCellSubclass.) Then, you can simply invoke NSSlider’s setCellClass
class method:
[NSSlider setCellClass:[MyCellSubclass class]]; |
All NSSliders created thereafter will use MyCellSubclass, until you call setCellClass:
again.
If you want to create generic NSSliders (ones that use NSSliderCell) in the same application as the customized NSSliders that use MyCellSubclass, there are two possible approaches. One is to invoke setCellClass:
as above whenever you’re about to create a custom NSSlider, resetting the cell class to NSSliderCell afterwards. The other approach is to create a custom subclass of NSSlider that automatically uses MyCellSubclass, as explained in the NSControl
class reference.
Copyright © 2008 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2008-10-15