Custom NSComboBox
Custom NSComboBox
- Subject: Custom NSComboBox
- From: Symadept <email@hidden>
- Date: Wed, 14 Oct 2009 19:09:39 +0800
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@hidden
_______________________________________________
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