Showing a currency value with readable text in a SwiftUI Mac app

I want to display a currency value in a SwiftUI app. I created a currency formatter. I created a text field, set its formatter to the currency formatter I created, and disabled the text field so people couldn't edit it.

let currencyFormatter: NumberFormatter = {
  let formatter = NumberFormatter()
  formatter.numberStyle = .currency
  return formatter
}()

TextField("Tip Amount", value: $tipAmount, formatter: 
    currencyFormatter)
  .disabled(true)

This works well on iOS. The currency formatter works correctly. I can see the value clearly and can't change it. But on Mac the text in the disabled text field is virtually unreadable.

I just want to display the value so I don't need a text field. I could use a Text view. But Text views don't support formatters as far as I can tell.

How do I show a currency value with SwiftUI on Mac with readable text?

Answered by Jonathan-C in 719017022

What about using the currencyFormatter.string(from: NSNumber) method to make a String and then just using that?

Accepted Answer

What about using the currencyFormatter.string(from: NSNumber) method to make a String and then just using that?

Converting the value to a string using currencyFormatter.string and displaying the string in a Text view worked. Thanks.

Showing a currency value with readable text in a SwiftUI Mac app
 
 
Q