The issue
I’m having trouble having a linear ProgressView show in a MenuBarExtra. Apparently, there is no counter-indication indicating that it is impossible to do so but I still fail to implement it.
Here is the minimal code structure:
import SwiftUI
import AppKit
@main
struct Menubar_InfoApp: App {
@State private var pct: String = "34%"
var body: some Scene {
MBE()
}
@SceneBuilder
func MBE() -> some Scene {
MenuBarExtra() {
VStack {
Text("Percentage: (pct)")
.padding()
ProgressView(value: Double(pct.dropLast(1)) ?? 0, total: 100)
.progressViewStyle(LinearProgressViewStyle())
.padding([.leading, .trailing])
.frame(width: 100)
}
} label: {
Text("sample")
}
}
}
Goal
I’m just looking for a way to have a ProgressView (linear) in a MenuBarExtra similar to:
What I’ve tried
- I don’t think the issue is linked with the value itself as I tried setting a hard value (doesn’t work).
- The issue doesn’t seem to be linked with the MenuBarExtra being called through a separate function, not directly in the body, but still, even if I move it there it fails to work.
Try this approach adding .menuBarExtraStyle(.window)
to your MenuBarExtra{...}
.
Works for me, tested on macOS 15.2, using Xcode 16.2.
@SceneBuilder
func MBE() -> some Scene {
MenuBarExtra() {
VStack {
Text("Percentage: (pct)").padding()
ProgressView(value: Double(pct.dropLast(1)) ?? 0, total: 100)
.progressViewStyle(LinearProgressViewStyle())
.padding([.leading, .trailing])
.frame(width: 100)
}
} label: {
Text("sample")
}
.menuBarExtraStyle(.window) // <-- here
}