Pergunta

I'm trying to create a custom button look.

From what I've gathered, NSButtonCell does the drawing, so I should actually be overwriting that instead.

But the issue is, my CustomButton class has other things like NSImage, mIsMouseOver etc. Currently the drawing is being done in the CustomButton class but I want to move it over to the cell.

question is, is there anyway I can access the image in the customButton class from the customButtonCell class so that I may use [image drawInRect:...]?

Regards, Han

Foi útil?

Solução

Your cell's drawWithFrame:(NSRect)frame inView:(NSView *)controlView method includes a reference to the NSView being drawn from which you can access the view's properties (such as image).

Outras dicas

Usual way is to store the data in the NSCell subclass. Base cell class even has an -(id)image property, so, your button class should call [[self cell] image] when it is queried for image.

Actually, since you are subclassing NSButton, it contains all you need, just override cell's drawing methods. And if you need an extra property - define it in the cell, wrap in the control.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top