I've seen answers to vertical resizing that involve autolayout, but the UILabel
s I'm creating are only needed at runtime. (I might need anywhere from zero to many of these labels.)
Examples (ignore the color)
- Short text (note same width as longer text):
- Longer text (note same width as shorter text example with more lines for add'l text):
If the text can fit in one line of fixed width, the label shouldn't need to resize vertically. But if there are more characters, the label should keep expanding vertically to fit these additional characters. The text should keep wrapping around line after line. The text should start in the top left corner of the label.
To be more specific:
let marker = GMSMarker(position: myLatLng)
// see http://stackoverflow.com/a/40211383/1168364 for imageWithView
marker.icon = imageWithView(label) // **how do i create this label?**
marker.map = map // map is a GMSMapView
These labels can be anywhere on the screen. This is for a map application where each label will be placed at a random location. The labels' locations have no relationship to one another.