NSButton添加下划线
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
NSBezierPath *linePath = [NSBezierPath bezierPath];
NSRect inRect = NSZeroRect;
inRect.origin = NSMakePoint(dirtyRect.origin.x, dirtyRect.size.height - 2);
inRect.size = NSMakeSize(self.frame.size.width, 2);
[linePath appendBezierPathWithRect:inRect];
if (_underLineColor == nil) {
[[NSColor whiteColor] set];
} else {
[_underLineColor set];
}
[linePath setLineWidth:2];
[linePath fill];
}
设置下划线颜色
- (void)setUnderLineColor:(NSColor *)underLineColor
{
if (_underLineColor == underLineColor) return;
_underLineColor = underLineColor;
[self setNeedsDisplay:YES];
}