xcode - Cocoa Programming: Adding a Rectangle to a Custom View (NSView) -


is there simple way add simple rectangle custom view without using custom nsview subclass it? along lines of:

  1. assign iboutlet (let's call colorwheelview) of nsview type customview
  2. in nsviewcontroller's initwithnibname use change draw rectangle:

    // pseudocode

    self.colorwheelview.addrectangle(myrectangle);

    self.redraw()

the way i've seen done (on site, , in book cocoa programming mac osx, pp. 241) making custom class custom view , modifying drawrect method... way accomplish this?

edit: not sure why formatting not being rendered correctly. i'm trying fix it.

it isn't hard roll own..

just add nsarray property nsview subclass, in drawrect method draw them either manually or using 1 of nsrectfilllist* methods provided appkit already.
(beware: take plain c array, not nsarray).

you wouldn't want manually trigger redraw outside view in sample code, though. keep things consistent addrectangle trigger redraw of view e.g. calling setneedsdisplay:.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -