0

text overlaying a map

I'm trying to display a map with information overlayed. To improve legibility on the map, I tried several ways (text shadows, outline text, darkening the map), but nothing really worked well – hence I tried to use a semitransparent box underneath the text.

I'm using the NSBackgroundColorAttributeName, which – as you can see in the screenshot – works fine for single line labels. In the multiline case though, the box seems to fill a whole line, even if there are no characters above.

Is this a bug in NSAttributedString, UILabel, or my usage of it? Do you know a better approach?

DrMickeyLauer
  • 4,455
  • 3
  • 31
  • 67

2 Answers2

1

What you are doing when adding a line break is essentially extending the UILabel with another line. So the outcome seen in the screenshot is only natural.

You cant solve it like this. I suggest you look into this solution: Highlight just the text in a UILabel

Community
  • 1
  • 1
dorian
  • 847
  • 5
  • 11
0

I have the opposite problem ... which is how to Force it to fill in the line!

In your case - all you need to do is to:

map_name.addAttribute( NSBackgroundColorAttributeName, value: nil,
range: nsRange_of_line_feed_char)

for the position of each end-of-line.

Antony
  • 11
  • 2