-1

I'm trying to create a legend that corresponds to colors on a map. No interaction. What I need is a colored square with text next to it. What I'm struggling with is how to go about creating this. I thought about programmatically creating each square but then I couldn't figure out how to set the text next to it. I then thought about a stack view with a view filled with a view colored and a label. Has anyone done something similar and if so how did you go about doing it?

Micah Montoya
  • 757
  • 1
  • 8
  • 24
  • You can use `UITableView`. So that you don't have to worry about positioning. It just works. – Sachin Vas Oct 19 '16 at 15:35
  • "I then thought about a stack view with a view filled with a view colored and a label." If you don't understand constraints, that is an _excellent_ idea. What happened when you tried it? – matt Oct 19 '16 at 15:51
  • @matt I don't understand what constraints has to do with this. Stackview was an idea so I could evenly space the views. I know of no way with constraints to do that. This is what I'm starting to do but I'm also looking for ideas. – Micah Montoya Oct 19 '16 at 16:00
  • "I know of no way with constraints to do that." I know you don't. But constraints is how you do it. UIStackView _makes_ the constraints for you, because you don't understand how to do it yourself. That is what a stack view _is_: it's a constraint-maker. That's why it's a great solution for you. – matt Oct 19 '16 at 16:02
  • @matt If you can give some proof showing even horizontal distribution using constraints that is as easily done as that of a stackview I and probably many others would like to see it. If there is a way to limit the amount of containers on UI I'm all for learning. I have found it for being done vertically but not horizontally. Do have any links showing this? I couldn't find any. – Micah Montoya Oct 19 '16 at 16:38
  • It _can't_ be "as easily done" as with a stack view. That is why stack views are good! But the stack view is in fact doing it: that is, what it is doing is something you _could_ have done. And before stack views existed, not so long ago, you had to. But don't! Anyway, if you want to understand how a stack view does even distribution under the hood, see my answer here: http://stackoverflow.com/a/20865342/341994 – matt Oct 19 '16 at 17:12

1 Answers1

0

You can create a square view with right background color, and than position your label next to it.

Olga Nesterenko
  • 1,324
  • 11
  • 15