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 {
var body: some View {
Text("Some text before \(Image(systemName: "waveform.circle")) plus some text after.")
}
}
But applying the modifier like this:
struct ContentView: View {
var body: some View {
Text("Some text before \(Image(systemName: "waveform.circle").rotationEffect(.radians(.pi * 0.5))) plus some text after.")
}
}
doesn’t compile and gives this error:
Instance method ‘appendInterpolation’ requires that ‘some View’ conform to ‘_FormatSpecifiable’
The Text interpolation expect an
Image
. When the.rotationEffect...
is applied it becomes aView
, and this is not valid.So an alternative is to rotate the SF before it is used in
Image
. This is what I ended up trying, using the code from one of the answers at: Rotating UIImage in Swift to rotate aUIImage
and using that in theImage
.It is a bit convoluted, and you will probably have to adjust the anchor/position. Perhaps someone will come up with a better solution. Until then it seems to works for me.