I’m trying to figure out how can I show only the first letter of the text?
struct MyText: View {
var body: some View {
Text("Hello")
.lineLimit(1)
}
}
This is how it should turn out
H
I tried using Line limit but as far as I know it only displays the text in one line
2
Answers
This can be done using the
first
property of the string:Every
String
has thefirst
property which returns the firstCharacter
of the string. Now becauseCharacter
s cannot be downcasted toString
, here’s what you need to do: