Mac开发-NSButton

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];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容