Exercises

  1. Change the color of the BlackView instance to the one with RGB values (0.5, 0.0, 0.5). Start by launching PB and searching for blackColor in the Find pane. After that, use a function other than NSRectFill( ) to display something in the view.

  2. Revise the BarView instance so that the bar goes up and down instead of right and left. Change the vertical slider attributes so that the bar can only have an integral height in the range 0 to 10.

  3. Take care of the PolygonView example problem that occurs when the window is resized very small by setting a minimum size for the window.

  4. Figure out why the PolygonView doesn’t always erase the old polygon that is drawn in the NSScrollView when it is made smaller. Fix the error. (Hint: The bug is closely related to the fact that the error manifests itself only when the PolygonView is being made smaller.)

  5. Insert text labels for the two sliders in the PolygonView example and make sure that the text behaves appropriately (no resize, attached to sliders). Then change the horizontal slider to a vertical one and make sure all the resizing and connections work properly.

  6. Build a new application with a window containing two overlapping views and several sliders. Connect sliders to the views and write code so that the user can change the RGB values and alpha channel of each view.

Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.