views:

150

answers:

0

Hi,

I am designing a custom NSComboBox to display the rect image as some ComboboxBg.png and set foreground (text) color to Red.

To render image I am doing the following things.

@interface CustomComboBoxCell : NSComboBoxCell {

} @end

@implementation CustomComboBoxCell - (void)drawWithFrame:(NSRect)bounds inView:(NSView *)controlView { NSLog(@"CPProfileComboBoxCell drawWithFrame[%f %f - %f %f]", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); NSRect imageRect = bounds;//[self drawingRectForBounds:bounds];//[self imageRectForBounds:bounds]; NSLog(@"Image rect [%f %f - %f %f]", imageRect.origin.x, imageRect.origin.y, imageRect.size.width, imageRect.size.height);

NSImage *bgImage = [NSImage imageNamed:@"ComboBox2"]; [bgImage drawInRect:imageRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; NSLog(@"Image drawn");

// Make attributes for our strings NSMutableParagraphStyle * aParagraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease]; [aParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; //[aParagraphStyle setAlignment:NSCenterTextAlignment];

// Title attributes: system font, 14pt, black, truncate tail NSMutableDictionary * aTitleAttributes = [[[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSColor blackColor],NSForegroundColorAttributeName, [NSFont systemFontOfSize:21.0],NSFontAttributeName, aParagraphStyle, NSParagraphStyleAttributeName, nil] autorelease];

// Make a Title string NSString * aTitle = [self stringValue];//[NSString stringWithString:@"Title"]; // get the size of the string for layout

// Icon box: center the icon vertically inside of the inset rect

NSLog(@"CellFrame:[%f %f] [%f %f]", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); NSRect aTitleBox = bounds;

[aTitleAttributes setValue:[NSColor yellowColor] forKey:NSForegroundColorAttributeName]; [aTitle drawInRect:aTitleBox withAttributes:aTitleAttributes]; }

@end

And If I dont draw the string by myself, the chosed item will not be shown. To make the combobox to show the value, I have to click inside once.

Can anybody help me to resolve this issue?

Thanks in advance Regards [email protected]