creating text field on the fly
creating text field on the fly
- Subject: creating text field on the fly
- From: Olivier Destrebecq <email@hidden>
- Date: Tue, 30 Jul 2002 14:50:05 -0500
I'm trying to create a clock control so that the user will be able to
enter time information. The control will look just as the clock control
of OS9 looked like.
My problem is that i create all my view that compose this clock on the
fly. They are placed correctly on the screen, and draw correctly except
that they all draw their content in their own frame and also at the top
left corner of the main view off the control.
i attached the creation code and the draing code at the end of the email.
Any pointers appreciated.
Olivier
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self)
{
// Initialization code here.
//the separator field
//
hourToMinuteSeparatorField = [[ NSTextField alloc]
initWithFrame: NSMakeRect(26, 0.0, 4, 22)];
[hourToMinuteSeparatorField setDrawsBackground: NO];
minuteToSecondSeparatorField = [[ NSTextField alloc]
initWithFrame: NSMakeRect(60, 0.0, 4, 22)];
[minuteToSecondSeparatorField setDrawsBackground: NO];
hourField = [[NSTextField alloc] initWithFrame:NSMakeRect(0.0,
0.0, 25, 22)];
[hourField setFormatter: [[[NSNumberFormatter alloc] init]
autorelease]];
minuteField = [[NSTextField alloc] initWithFrame: NSMakeRect(34,
0.0, 25, 22)];
[minuteField setFormatter: [[[NSNumberFormatter alloc] init]
autorelease]];
secondField = [[NSTextField alloc] initWithFrame: NSMakeRect(68,
0.0, 25, 22)];
[secondField setFormatter: [[[NSNumberFormatter alloc] init]
autorelease]];
AMPMField = [[NSTextField alloc] initWithFrame: NSMakeRect(102,
0.0, 25, 22)];
[AMPMField setEditable: NO]; //disable it as there are only two
values, they will be set with the steper only
//the stepper used to modify all those
//
stepper = [[NSStepper alloc] initWithFrame: NSMakeRect(133, 0.0,
13, 22)];
//add them, to their super view
//
//[self addSubview:[hourField autorelease]];
[self addSubview:[minuteField autorelease]];
[self addSubview:[secondField autorelease]];
[self addSubview:[AMPMField autorelease]];
//now the separator
//
[self addSubview:[hourToMinuteSeparatorField autorelease]];
[hourToMinuteSeparatorField setBezeled: NO];
[hourToMinuteSeparatorField setDrawsBackground: YES];
[hourToMinuteSeparatorField setEditable: NO];
[hourToMinuteSeparatorField setSelectable: NO];
[self addSubview:[minuteToSecondSeparatorField autorelease]];
[minuteToSecondSeparatorField setBezeled: NO];
[minuteToSecondSeparatorField setDrawsBackground: YES];
[minuteToSecondSeparatorField setEditable: NO];
[minuteToSecondSeparatorField setSelectable: NO];
[self addSubview:[stepper autorelease]];
//set up the formatter for the minute and the seconds
//
[[secondField formatter] setMaximum: [NSDecimalNumber
decimalNumberWithDecimal:[[NSNumber numberWithInt: 60] decimalValue]]];
[[secondField formatter] setMinimum: [NSDecimalNumber
decimalNumberWithDecimal:[[NSNumber numberWithInt: 0] decimalValue]]];
[[secondField formatter] setFormat:@"00"];
[[minuteField formatter] setMaximum: [NSDecimalNumber
decimalNumberWithDecimal:[[NSNumber numberWithInt: 60] decimalValue]]];
[[minuteField formatter] setMinimum: [NSDecimalNumber
decimalNumberWithDecimal:[[NSNumber numberWithInt: 0] decimalValue]]];
[[minuteField formatter] setFormat:@"00"];
[[hourField formatter] setFormat:@"00"];
[self setDefaultValue];
}
return self;
}
- (void)drawRect:(NSRect)rect
{
// just ask each piece to draw itself
//
[hourToMinuteSeparatorField drawRect: NSMakeRect(26, 0.0, 4, 22)];
[minuteToSecondSeparatorField drawRect: NSMakeRect(60, 0.0, 4, 22)];
[hourField drawRect: NSMakeRect(0.0, 0.0, 25, 22)];
[minuteField drawRect: NSMakeRect(34, 0.0, 25, 22)];
[secondField drawRect: NSMakeRect(68, 0.0, 25, 22)];
[AMPMField drawRect: NSMakeRect(102, 0.0, 25, 22)];
[stepper drawRect: NSMakeRect(133, 0.0, 13, 22)];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.