gpt4 book ai didi

objective-c - 使 NSLevelIndicator 绘制圆角边缘

转载 作者:行者123 更新时间:2023-12-03 17:12:12 25 4
gpt4 key购买 nike

我想为我的 NSLevelIndicator 创建一个自定义类,它只是将边缘四舍五入。 (即像圆角矩形按钮)我创建了一个自定义类,我知道我必须在

-(void)drawRect:(NSRect)dirtyRect;

方法,但我完全不知道如何实现这一点,我希望有人对此有想法。

最佳答案

Output

@interface DILevelIndicatorCell : NSLevelIndicatorCell

@property ( readwrite, assign ) BOOL drawBezel;

@property ( readwrite, assign ) BOOL verticalCenter;

@end
<小时/>
- ( void )drawWithFrame:( NSRect ) rcCellFrame inView:( NSView* ) pControlView
{

NSRect rcInterior = rcCellFrame;

if( _drawBezel )
{
[ self _drawBezelWithFrame:rcCellFrame ];

rcInterior = NSInsetRect( rcCellFrame, 3, 3 );
}

if( _verticalCenter )
{
CGFloat i = ( NSHeight( rcInterior ) - [ self cellSize ].height ) / 2;
rcInterior.origin.y += i;
rcInterior.size.height -= i;
}

[ super drawWithFrame:rcInterior inView:pControlView ];
}

- ( void )_drawBezelWithFrame:( NSRect ) dirtyRect
{

CGFloat fRoundedRadius = 10.0f;

NSGraphicsContext* ctx = [ NSGraphicsContext currentContext ];
[ ctx saveGraphicsState ];
{
NSBezierPath* pPath = [ NSBezierPath bezierPathWithRoundedRect:dirtyRect
xRadius:fRoundedRadius
yRadius:fRoundedRadius ];
[ pPath setClip ];

[ [ NSColor colorWithCalibratedRed:0.9 green:0.9 blue:0.95 alpha:1.0 ] setFill ];
NSRectFillUsingOperation ( dirtyRect, NSCompositeSourceOver );

[ [ NSColor colorWithCalibratedRed:0.7 green:0.7 blue:0.85 alpha:1.0 ] setFill ];
[ pPath setLineWidth:1 ];
[ pPath stroke ];
}
[ ctx restoreGraphicsState ];
}

关于objective-c - 使 NSLevelIndicator 绘制圆角边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20713022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com