Re: Creating subviews programmatically ?
Re: Creating subviews programmatically ?
- Subject: Re: Creating subviews programmatically ?
- From: Vince Ackerman <email@hidden>
- Date: Mon, 26 Nov 2007 08:59:07 -0800
Okay, thanks. I was hoping to avoid going down a particular road and
then end up back-tracking and re-doing a lot of work later.
I do want to be able to intercept mouse over events and have pop up
(tool tips?) box with a details about the schedule for that day.
That's why I thought of subviews...
I'm still trying to get my (old) brain around Obj C and Cocoa.
I'll check out the example you referenced.
Vince
On Nov 26, 2007, at 08:31, I. Savant wrote:
Is this possible or would the overhead and drawing time be
prohibited? Would I start by adding subviews to the main view ,
giving each it's own bounds rect, then resize the individual subviews
as the main view was re-sized? Is auto sizing taken care of by the
main view?
Of course it's possible to do this but why? The overhead would be
greater for 30-some individual "day" views.
If you have a "Calendar View" that knows its own grid, why not have
routines something like this:
- (void)drawRect:(NSRect)rect // draws portion of the overall view
- (void)drawDay:(id)someDayObject inRect:(NSRect)rect // draws a day
object (that knows how to draw its own subparts) in a given rect
The -drawRect: method would determine which day rects need redrawn
(based on the rect Cocoa asked it to draw) and draw each "day" object
into its designated rect. Your "day" object (or the calendar view) can
then break the task down further:
// Assume this method belongs to your "Day" class
- (void)drawView:(id)someView inRect:(NSRect)rect
selected:(BOOL)selected ... other options...
{
// Lock focus on "someView"
// If I'm selected, draw a "selected" color background ...
// Draw my date number ...
// For every event, draw it in its own color ...
// Unlock focus from "someView"
// ...
}
Of course the proper way to do this is to use NSControl and NSCell
subclasses (ie a "Calendar" control subclass and a "Day" cell
subclass). This will make it easier to handle selection state,
mouse/key events, etc.
In its simplest sense, however, look at the Sketch example in your
/Developer/Examples folder. This does the same thing with a "Canvas"
and "Shape" objects, where a class of "Shape" knows how to draw itself
in a rect of a view with certain options when asked.
--
I.S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden