BarView: An NSView with a Scaled Coordinate System
In this section we’ll subclass NSView to create a class called BarView to demonstrate a scaled coordinate system. A BarView object will display a simple bar graph that draws a graph between the range to 100, depending on the value of a slider. It will scale its coordinate system and control redrawing with the appropriate display methods. We’ll use the same ViewDemo project we created for BlackView so that we won’t have to go through the project-creation process again.
Back in IB, remove all BlackView instances from your ViewDemo window (select them one by one and type Control-X).
Select the NSView class under the Classes tab of IB’s Nib File window and subclass NSView by choosing IB’s Classes → Subclass NSView menu command.
Change the name of the new subclass from “MyView” to “BarView”.
Drag a CustomView icon from IB’s Cocoa-Containers palette and drop it in the empty window.
Type Command-1, then change the class of the CustomView to BarView in the NSView (Custom) Info panel.
Resize the BarView instance, as shown in Figure 15-5.
Drag a vertical slider from IB’s Cocoa-Other palette and drop it next to the BarView, as shown in Figure 15-5.
With the slider selected, type Command-1 and note that the slider has a default range (Minimum/Maximum) from 0.0 to 100.0 and a Current setting of 50.0.
Change the Current value of the slider to 0.0 in the NSSlider Info panel.
Make sure that the Marker Values Only checkbox is not checked so that ...