NSButton custom drawing messed up text rendering

I will subclass NSButton / NSButtonCell and everything works fine, but at least when drawing Retina, as soon as I implement any of the drawing functions in NSButton or NSButtonCell, the text change changes regardless of whether I make some custom text drawing or delegate directly to the super implementation.

button pattern

As you can see, the text is much finer, just changing the smoothing.

When I look at this in Xcode Reveal-rip, I see that the text is embedded in NSButtonTextField when none of the drawing methods are overridden. As soon as any of the drawing methods is overridden, the NSButtonTextField disappears.

None of this happens when I paste the background layer behind the button text and set

button.isBorderd = false

but I don’t really like it.

"" , ? , string, , -?

/

+4
2

, , , .

NSTextField :

_titleTextField = [[NSTextField alloc] initWithFrame:NSZeroRect];
[_titleTextField setBordered:NO];
[_titleTextField setDrawsBackground:NO];
[_titleTextField setFont:[NSFont systemFontOfSize:13]];
[_titleTextField setTextColor:[FantasticalColors color:@"dimLabelTextColor"]];
[_titleTextField setStringValue:[self title]];
[_titleTextField setEditable:NO];
[_titleTextField setFocusRingType:NSFocusRingTypeNone];
[self addSubview:_titleTextField];

drawRect, . , , .

0

, . Info.plist

,

Apple

:
Before image

, : After image

0

Source: https://habr.com/ru/post/1660067/


All Articles