Reputation: 261
I need some help on how to generate a single line text in a circular path using SwiftUI. I am trying to replicate the curved text in these Image. Is this possible in SwiftUI? Thanks.
Upvotes: 10
Views: 7266
Reputation: 261
Found a solution to my question. Credits to Tobias Due Munk for posting his prototype for CurvedText using SwiftUI. His solution can be found here https://github.com/duemunk/CrookedText
Example usage:
CrookedText(text: "Hello, world!", radius: 10)
Upvotes: 16
Reputation: 17534
calculate position of each character, see How to get position of each character in SwiftUI Text and related answers and discussions, to know the limitations
calculate required position and rotation of each character on the path you would like to follow (for circle it is very easy to be done) with help of step 1 (use the distance along the path as a parameter)
position and rotate each character as here Positioning View using anchor point
I know that answers with links, as already mentioned by "Ru Chem Chong", is not the best, but answer your question is really complex task and explanation needs more than space available here.
Upvotes: 1
Reputation: 4346
No, Swift UI doesn't provide any way to do that as of now. So as @fulvio pointed out you must do it Swift UIKit way .
You can later use UIViewRepresentable to integrate it in your SwiftUI Project Refer Swift UI interfacing with UIKit by Apple Inc.
Upvotes: 1