Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - How to set Voiceover Language on view basis?

In my SwiftUI App I have a TextView based on UIViewRepresentable. TextView displays text in different languages, depending on user action. All the text is always in the same language, i.e. it does not mix text of different languages at a time.

Now, I need to support VoiceOver and the problem is that TextViews text is always spoken in users preferred language, which is often inappropriate. I want to set the TextView's VoiceOver language depending on its text language without affecting my other views.

How to set VoiceOver language in SwiftUI on a view basis ?

Thanks

like image 207
Chris Avatar asked Dec 06 '25 08:12

Chris


1 Answers

I'm not sure what you mean by TextView in a SwiftUI context but... if you use a Text view, you can set the Text view's locale as follows:

Text(verbatim: "Hello")
  .font(.headline)
  .environment(\.locale, .init(identifier: "en"))

Source: Use Your Loaf > SwiftUI Accessibility Language

like image 114
Adil Hussain Avatar answered Dec 08 '25 22:12

Adil Hussain