|
Good evening everyone. Guys, tell me how to generate points in the text? Example: proteins/100 g................................. 1.3 g carbohydrates/100 g....................... 1.3g |
|
You would need to get the length of the longest string first and then fill the blanks with dots. I don't know if there is a library or a function in Foundation which can do this. But there is a bit caveat! You need a font where every symbol has the same width aka monospaced. Otherwise, the result would depend on the used font. F.e. your first line has 54 columns and your second line only has 48 columns. I hope you understand what I mean. And with a monospaced font your lines don't line up... |
|
Steven gets right to the point....
PlaygroundsTry this code in Playgrounds. As @Hatsushira points out, to get a reasonable alignment, you need to use a
Keep coding!Please let us know how you solved your problem! |
|
I am very grateful for your advice and help!!! Got perverted and did this....
|
|
Hi Steven, Maybe your case is more complicated than I imagine, but if you just need to display lables why to make all those calculations. Maybe simple approach will be much easier. About the cost? Well I do not think that all those dots, if you make them even 1000 to make sure ipad or other device looks good as well, will take so "much" memory.
|
|
Hi, Yuri! Thanks for the help. But I have already implemented it in this clumsy way. Since I have text in two lines. I simply compared the width of the text block to the length of the words and if a certain number of words is greater than the width. Then I take the previous value and substitute it in the mask 🧐 Clumsy, but it works! Although, following your example, you can calculate the length and enter points, I didn’t think of that. |
SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.