Cocoa:在 Lion 上子类化 NSProgressIndicator

发布于 2024-12-09 05:09:28 字数 386 浏览 0 评论 0原文

我有一个问题让我发疯。我想以“Bar”形式对 NSProgressIndicator 进行子类化,以根据几个逻辑状态更改进度条的颜色。为此,我基本上像往常一样重写 -drawRect: 。然而,一件非常奇怪的事情发生在狮子身上。即使我的 -drawRect 只是通过 [super drawRect:] 调用超类的实现并且不执行任何其他操作,整个进度条也将使用所使用的样式显示狮子之前。如果您还记得,在 Lion 中,进度条样式已从之前的玻璃样式变为更加平坦和时尚的外观。

同样,只需重写 -drawRect 只调用超类的实现即可将进度条的样式更改为 Leopard 的样式。有谁知道发生了什么以及我如何解决这个问题?

I have a problem that is driving me crazy. I want to subclass NSProgressIndicator in its "Bar" form to change the color of the progress bar based on a couple of logic states. For that i basically override the -drawRect: as usual. However a very strange thing happens on Lion. Even if my -drawRect just calls the superclass' implementation via [super drawRect:] and does nothing else at all the whole progress bar will be displayed using the style that was used before Lion. If you remember, with Lion the progress bar style has changes to a more flat and sleek look from the prior glassy one.

Again, just overriding -drawRect to do nothing but to call the superclass' implementation changes the style of the progress bar to Leopard's. Does anyone have a slightest idea of what is going on and how i can fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Oo萌小芽oO 2024-12-16 05:09:28

让进度指示器支持图层并应用 Core Image 滤镜来重新着色怎么样?

How about making the progress indicator layer-backed and applying a Core Image filter to recolour it?

喜爱皱眉﹌ 2024-12-16 05:09:28

CustomeProgressIndicator.h:

#import <Cocoa/Cocoa.h>

@interface CustomProgressIndicator : NSView {

    double m_minValue;
    double m_maxValue;
    double m_value;
}

- (void)setMaxValue:(double)newMaxValue;
- (void)setMinValue:(double)newMinValue;
- (void)setDoubleValue:(double)newDoubleValue;
- (void)drawRect:(NSRect)dirtyRect;   
@end

CustomProgressIndicator.m:

#import "CustomProgressIndicator.h"

@implementation CustomProgressIndicator

- (void)setMaxValue:(double)newMaxValue
{
    m_maxValue = newMaxValue;
}

- (void)setMinValue:(double)newMinValue
{
    m_minValue = newMinValue;
}

- (void)setDoubleValue:(double)newDoubleValue
{
    m_value = newDoubleValue;
    [self setNeedsDisplay:YES];
}

- (void)drawRect:(NSRect)dirtyRect
{
    [[NSColor grayColor] set];
    [NSBezierPath fillRect:dirtyRect];

    double width = ((m_value - m_minValue) / (m_maxValue - m_minValue));
    CGRect bar = dirtyRect;
    bar.size.width *= width;

    [[NSColor darkGrayColor] set];
    [NSBezierPath fillRect:bar];    
}

CustomeProgressIndicator.h:

#import <Cocoa/Cocoa.h>

@interface CustomProgressIndicator : NSView {

    double m_minValue;
    double m_maxValue;
    double m_value;
}

- (void)setMaxValue:(double)newMaxValue;
- (void)setMinValue:(double)newMinValue;
- (void)setDoubleValue:(double)newDoubleValue;
- (void)drawRect:(NSRect)dirtyRect;   
@end

CustomProgressIndicator.m:

#import "CustomProgressIndicator.h"

@implementation CustomProgressIndicator

- (void)setMaxValue:(double)newMaxValue
{
    m_maxValue = newMaxValue;
}

- (void)setMinValue:(double)newMinValue
{
    m_minValue = newMinValue;
}

- (void)setDoubleValue:(double)newDoubleValue
{
    m_value = newDoubleValue;
    [self setNeedsDisplay:YES];
}

- (void)drawRect:(NSRect)dirtyRect
{
    [[NSColor grayColor] set];
    [NSBezierPath fillRect:dirtyRect];

    double width = ((m_value - m_minValue) / (m_maxValue - m_minValue));
    CGRect bar = dirtyRect;
    bar.size.width *= width;

    [[NSColor darkGrayColor] set];
    [NSBezierPath fillRect:bar];    
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文