Mac开发-NSButton

2019-08-02  本文已影响0人  只爱随便看看

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];
}
上一篇 下一篇

猜你喜欢

热点阅读