美文网首页
Mac开发-NSButton

Mac开发-NSButton

作者: 只爱随便看看 | 来源:发表于2019-08-02 09:56 被阅读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];
}

相关文章

网友评论

      本文标题:Mac开发-NSButton

      本文链接:https://www.haomeiwen.com/subject/hmykdctx.html