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:
- assign iboutlet (let's call colorwheelview) of nsview type customview
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
Post a Comment