NSBackgroundColorAttributeName用于多行属性字符串标签 [英] NSBackgroundColorAttributeName for multiline attributed strings labels

查看:228
本文介绍了NSBackgroundColorAttributeName用于多行属性字符串标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示覆盖了信息的地图.为了提高地图的易读性,我尝试了几种方法(文本阴影,轮廓文本,使地图变暗),但是没有什么真正起作用的-因此,我尝试在文本下方使用半透明的框.

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.

我正在使用NSBackgroundColorAttributeName,正如您在屏幕快照中所见,它对于单行标签效果很好.但是,在多行情况下,即使上面没有字符,该框也似乎填满了整行.

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.

这是NSAttributedStringUILabel中的错误还是我的用法?您知道更好的方法吗?

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

推荐答案

添加换行符时的操作实际上是在用另一行扩展UILabel.因此,在屏幕截图中看到的结果是自然的.

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.

您不能像这样解决它.建议您研究以下解决方案:仅突出显示UILabel

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

这篇关于NSBackgroundColorAttributeName用于多行属性字符串标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆