objective c - NSComboBox - problems with background when selected -


i'm ios developer, , i'm programming desktop app mac osx. still don't have experience view's components of osx, maybe it's silly or easy question, have made little research problem , haven't found solution yet.

here's problem:

i have custom specialization of nsview, used view of content viewcontroller used in nspopover.

inside view, i'm calling "popoverbackgroundview", painted inside drawrect red background, , calculated minor rect , painted gray-like color. here's code:

- (void)drawrect:(nsrect)dirtyrect {     [[nscolor colorwithdevicered:174/255.0 green:72/255.0 blue:72/255.0 alpha:1.0] setfill];     nsrectfill(dirtyrect);      [[nscolor colorwithdevicered:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0] setfill];     nsrectfill(nsmakerect(border_width, border_width, dirtyrect.size.width - 2*border_width, dirtyrect.size.height - 2*border_width)); } 

so, inside popoverbackgroundview.m i'm programatically creating nscombobox. combobox have numbers 1 10. when allocate it, seems fine:

enter image description here

the problem is, after select options inside combobox, it's background somehow "goes away" became transparent, don't know, , become this:

enter image description here

please notice red-like frame (background color of view) around nscombobox, appeared after select something.

here's code i'm allocation combobox , initializing it:

- (id)initwithframe:(nsrect)frame {     self = [super initwithframe:frame];     if (self) {           (...)          self.combobox = [[nscombobox alloc] initwithframe:cgrectmake(15, frame.size.height - 55, 90, 25)];         self.combobox.delegate = self;         [self.combobox setdrawsbackground:no];         [self.combobox setselectable:yes];         [self.combobox seteditable:no];          (int = 1; i<=10; i++)         {             nsstring *mystr = [nsstring stringwithformat:@"%d", i];             [self.combobox additemwithobjectvalue:mystr];         }          [self addsubview:self.combobox];      }      return self; } 

any idea how can 'fix' "selected background"? want it's selected state equals normal state, i. e. ,the combobox should first image, after selection.

is there wrong allocation code? mission? i'm thinking property i'm not using or initializing, couldn't find yet.

thanks in advance,

just give feedback, able resolve problem.

i don't know why, problem caused because way drawing border in drawrect. somehow, these code

[[nscolor colorwithdevicered:174/255.0 green:72/255.0 blue:72/255.0 alpha:1.0] setfill]; nsrectfill(dirtyrect); 

were been propagated subviews, don't know if setfill or nsrectfill. so, "background" of nscombobox been painted color.

after seeing post :adding border , rounded rect in nsview changed draw rect this:

- (void)drawrect:(nsrect)dirtyrect {     nsbezierpath *background = [nsbezierpath bezierpathwithroundedrect:self.bounds xradius:10 yradius:10];     [[nscolor colorwithdevicered:174/255.0 green:72/255.0 blue:72/255.0 alpha:1.0] set];     [background setlinewidth:10];     [background stroke]; } 

and working fine now, wanted. now, after select combobox, no strange background been drawing.

enter image description here

if knows whey happening previous code, please, let me know.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -