Post

Replies

Boosts

Views

Activity

Reply to [SwiftUI] Not able to customize font size on label of MenuBarExtra
I ran into the same issue. I found a workaround that I don't like but does work for what I want to do. I save the Text that I want into a View variable and render it into a cgImage and use that for the Label. I couldn't use ImageRenderer in the "label:" block, it gave an obscure error. Here is an edited excerpt from the code I used. You might have to play with padding and/or Spacer() to make it fit properly on the status bar. Hopefully you find it useful. var body: some Scene { MenuBarExtra() { Text("...") } label: { updateTitleImage(titleText: title!) } .menuBarExtraStyle(.window) } struct updateTitleImage: View { var titleText: String var body: some View { // I used a font that's twice as large as what I want and then use a scale of 2 to make the text look smoother let title = Text(titleText).font(Font.custom("Monaco", size: 16.0)).foregroundColor(Color.white).padding(.bottom) let renderer = ImageRenderer(content: title) let cgImage = renderer.cgImage Image(cgImage!, scale: 2, label: Text("")) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’23