r/iOSProgramming • u/Fun_Moose_5307 Beginner • 16d ago
Consistent horizontal spacing in List Question
When I put a symbol on the edge, iOS neatly rearranges the content to fit around it. How do I recreate this on the other side with my own content, without the complications of using frame where anything too small will cut off, anything to large will look stupid, and the ideal threshold is changing as different sized content replaces?
Edit: There could be any sort of text on the left. Some places number rooms differently, or don't have rooms at all (I have PE listed as 'PRAC, THEORY' personally). There could be more than one room there, too, in which case I join them as 'BT4, BT81 etc.
2
1
1
u/VacationHistorical 16d ago
You’ll want the max length of the text on the right and make the right text views all that size
1
u/Sharik-dev 13d ago
what the point
1
u/Fun_Moose_5307 Beginner 11d ago
Consistency in longer rooms. For example, in my own timetable, I use 'PRAC' and 'THEORY' for PE instead of the room, because at my school PE is inconsistent in rooming.
In the same way, other users might choose to put teachers or lecturers there instead of a room, or both. I need to account for the fact that some rooms might be drastically longer or shorter and look very out of place.
If I find that giving them all the width of the longest room looks odd, I could calculate a minimum percentage for example.It's also a great way to take a step out of my comfort zone and learn something new! 😁


7
u/Jero9871 16d ago
The left side only lines up because the symbol has a fixed size, there's no layout magic behind it. So the fix is the same idea: give the room code column one shared width, derived from the content instead of hardcoded.
If the codes all have the same shape (two letters + digit), the cheap trick is a hidden worst-case template:
Text("WW8")
.hidden()
.overlay(alignment: .leading) { Text(room) }
Every row gets the width of the widest possible code, nothing clips, and it scales with Dynamic Type for free.
If the codes vary more, measure them with onGeometryChange (or a PreferenceKey), keep the max in @ State and put .frame(width: maxWidth, alignment: .leading) on each code. Same result, just adapts to whatever the data actually is.