Swift:设置 NSProgressIndicator 的进度

iph*_*aaw 2 macos nsprogressindicator swift

我尝试使用以下方法设置我自己的 NSProgressIndicator。

class ProgressViewController : NSViewController 
{
    override func loadView()
    {
        let view = NSView(frame: NSMakeRect(0,0,300,120))
        view.wantsLayer = true
        view.layer?.borderWidth = 0
        self.view = view

        let text = NSTextField(frame: NSRect(x: 20, y: 45, width: 260, height: 20))
        text.drawsBackground = true
        text.isBordered = false
        text.backgroundColor = NSColor.controlColor
        text.isEditable = false
        self.view.addSubview(text)
        text.stringValue = "Progress Text"

        let indicator = NSProgressIndicator(frame: NSRect(x: 20, y: 20, width: 260, height: 20))
        indicator.minValue = 0.0
        indicator.maxValue = 100.0
        indicator.doubleValue = 33.0
        self.view.addSubview(indicator)
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是指标始终显示为满。我错过了一个技巧吗?

Cod*_*ent 5

默认样式是不确定的。将其设置为 false,一切都应该没问题:

indicator.isIndeterminate = false
Run Code Online (Sandbox Code Playgroud)