Questions tagged [swiftui-text]

60 questions
2
votes
2 answers

How to get rid of vertical text padding in SwiftUI?

I want to make a rectangle with text inside. the rectangle should be pinned to the right and left side of the display (or superview). It's height should be determined by the text. I tried the following code: struct DescriptionView: View { var…
WalterBeiter
  • 2,021
  • 3
  • 23
  • 48
2
votes
0 answers

How do I prevent VoiceOver from reading the text in a SwiftUI Text view on iOS?

For various reasons, I have to use AVSpeechSynthesizer in SwiftUI to read text for visually impaired users. How can I prevent VoiceOver from reading the text in the Text view, without making it invisible to Accessibility? Ideally I'd like to define…
Melodius
  • 2,505
  • 3
  • 22
  • 37
2
votes
0 answers

Evenly distribute wrapped text between lines in SwiftUI

How can I tell SwiftUI that when text wraps, I'd like all the lines to be as close to equal length as possible? For example, I don't want this: The quick brown fox jumps over the lazy dog Even if there is enough horizontal space to fit everything…
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
2
votes
2 answers

Make a text element always "two lines"

I have a vertical stack like this VStack Text(lineA) .lineLimit(2) Text(lineB) Text(lineC) } Don't ask me why. My bosses decided that they want the first Text always with two lines, even if the lineA variable has no characters to make…
Duck
  • 34,902
  • 47
  • 248
  • 470
2
votes
1 answer

SwiftUI: how can to calculate the width of a Text view?

I have unknown number of Text views I need to account for (as many hours that pass during sleep). Each Text view is just a single hour e.g. Text("12"), Text("1") etc. I need to know the width of all the combined hour Text Views so I can subtract…
GarySabo
  • 5,806
  • 5
  • 49
  • 124
2
votes
2 answers

How to use a NumberFormatter in SwiftUI?

I'm trying to use the below NumberFormatter but can't figure out how to use it in a Text view? Everything online relates to a TextView. static let numberFormat: NumberFormatter = { let numberFormatter = NumberFormatter() …
GarySabo
  • 5,806
  • 5
  • 49
  • 124
2
votes
2 answers

How to reserve space for Text in SwiftUI

I have a sheet that shows progress for uploading files. It looks like this: As you can see, the line that changes ("3.4 MB of 13.9...") gets truncated. This is because it starts off with one width, but then can grow with different numbers in the…
Rob N
  • 15,024
  • 17
  • 92
  • 165
2
votes
3 answers

Get frame of a word in SwiftUI Text

I want to find the position of a word in a sentence so that I can set a frame for that word. Like so for example: Is it currently possible to do this in SwiftUI I wrote some code and this is what I got import SwiftUI struct ContentView: View { …
Beslan Tularov
  • 3,111
  • 1
  • 21
  • 34
1
vote
2 answers

Conditionally rendering Text view with a large string causes performance issue

My SwiftUI app has a network log screen that shows network requests sent and recorded by the app. There is a button to toggle the visibility of each request. Requests are serialized and stored as strings, so they can be displayed on this…
Jake Loew
  • 81
  • 7
1
vote
1 answer

How to format Text bold from a String in SwiftUI?

i have this example code: let longString = """ imagine here is a really really long Text. **This is in bold**. This is not in bold """ struct ContentView: View { var body: some View { Text(longString) } } But…
Mobias
  • 31
  • 3
1
vote
2 answers

Is there a way to use string interpolation with an SF Symbol that has a modifier on it?

I want to use string interpolation on an SF Symbol that has a rotationEffect(_:anchor:) modifier applied to it. Is it possible to do this? Without the modifier this type of string interpolation works fine (in Swift 5.0): struct ContentView: View { …
1
vote
1 answer

SwiftUI Text with DateFormatter doesn't respect TimeZone

I need to display the date/time of an event with a toggle that lets the user switch between their current timezone and the timezone the event takes place in. I'm trying to use the SwiftUI text formatters but can't figure out how to make it work for…
Matthew Folbigg
  • 137
  • 1
  • 7
1
vote
1 answer

SwiftUI: A list with a DatePicker and Text mangles the display

On iOS 15, if you display a List of VStacks with a Text and DatePicker as below @main struct WeirdListDatePickerProblem: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { …
mmm111mmm
  • 3,607
  • 4
  • 27
  • 44
1
vote
1 answer

How to create an enum based .textStyle(.title) modifier for Text(...) components in SwiftUI?

I want to implement a modifier setting for Texts in a similar way as it already exists for Buttons. Aka: Button( ... ) .buttonStyle(.plain) // <-- .plain and not PlainStyle() Problem Of course I cannot use an opaque which is not really the same.…
Tobonaut
  • 2,245
  • 2
  • 26
  • 39
1
vote
1 answer

SwiftUI Navigation Title Text Priority (of two texts)

I have two texts that I would like to display in a navigation title: ... .navigationTitle(Text(getTitle()) + Text(" (\(selection + 1)/\(sequenceObject.homeElements.count))")) However, the first text could become too large after user input…
SwiftUI_Max
  • 201
  • 2
  • 6