什么原因导致白色边框应用于系统菜单中显示的NSProgressIndicator? [英] What causes a white border to be applied to an NSProgressIndicator displayed in the system menu?

查看:155
本文介绍了什么原因导致白色边框应用于系统菜单中显示的NSProgressIndicator?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是当我创建一个NSProgressIndicator和使用 NSStatusItem -setView:方法显示它

This is what happens when I create an NSProgressIndicator and use NSStatusItem's -setView: method to display it in the menubar area while I'm performing an action:

什么原因导致此边框显示,如何删除它?预期的结果是控件是透明的。

What causes this border to be displayed, and how can I remove it? The intended result is that the control be transparent.

这里是我使用的代码:

NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] init];

[progressIndicator setBezeled: NO];
[progressIndicator setStyle: NSProgressIndicatorSpinningStyle];
[progressIndicator setControlSize: NSSmallControlSize];
[progressIndicator sizeToFit];
[progressIndicator startAnimation: self];
[statusItem setView: progressIndicator]; // statusItem is an NSStatusItem instance
...
[statusItem setView: nil];
[progressIndicator stopAnimation: self];
[progressIndicator release];


推荐答案

NSProgressIndicator ,尽管它也是一个 NSView 。创建一个新视图,调整精度,在该视图中定位状态指示器,并将封装视图传递给 - [NSStatusItem setView:] 。这是我的实现。

Don’t scale the NSProgressIndicator though it’s also an NSView. Create a new view that resizes fine, position the status indicator in that view, and pass the enclosing view to -[NSStatusItem setView:]. Here is my implementation.

NSStatusItem + AnimatedProgressIndicator.m

- (void) startAnimation {

    NSView *progressIndicatorHolder = [[NSView alloc] init];

    NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] init];

    [progressIndicator setBezeled: NO];
    [progressIndicator setStyle: NSProgressIndicatorSpinningStyle];
    [progressIndicator setControlSize: NSSmallControlSize];
    [progressIndicator sizeToFit];
    [progressIndicator setUsesThreadedAnimation:YES];

    [progressIndicatorHolder addSubview:progressIndicator];
    [progressIndicator startAnimation:self];

    [self setView:progressIndicatorHolder];

    [progressIndicator center];

    [progressIndicator setNextResponder:progressIndicatorHolder];
    [progressIndicatorHolder setNextResponder:self];

}

- (void) stopAnimation {

    [self setView:nil];

}

- (void) mouseDown:(NSEvent *) theEvent {

    [self popUpStatusItemMenu:[self menu]];

}

- (void) rightMouseUp:(NSEvent *) theEvent {}
- (void) mouseUp:(NSEvent *) theEvent {}
…

我添加了一个自定义方法, - [NSView center] code>,它执行以下操作:

I added a custom method, -[NSView center], which does the following:

@implementation NSView (Centering)

- (void) center {

    if (![self superview]) return;

    [self setFrame:NSMakeRect(

        0.5 * ([self superview].frame.size.width - self.frame.size.width),
        0.5 * ([self superview].frame.size.height - self.frame.size.height), 

        self.frame.size.width, 
        self.frame.size.height

    )];

}

@end

这篇关于什么原因导致白色边框应用于系统菜单中显示的NSProgressIndicator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆