【问题标题】:UILabel extra spaces before textUILabel 文本前多余的空格
【发布时间】:2015-03-17 12:53:57
【问题描述】:

我有一个标签,如果我在标签上添加文本,它会在文本的开头添加一个额外的空格,应用程序仅支持纵向。尝试了以下解决方案,但没有用。附上图片供参考。

我在 xib 中创建了这个标签 行数 2 具有前导、尾随、底部空间到容器的约束,高度不固定,

并设置文本像

dealName.text = "Cup of Coffee with A asdf asd asdf adsf ads fad"

UILabel extra spaces before and after text ios

UIlabel shows extra space before text

多行UILabel

单行UILabel

【问题讨论】:

  • 请检查标签字符串可能是标签字符串包含空格。
  • 仔细检查,没有空格。
  • 检查标签对齐方式
  • 标签左对齐。看到第二行左对齐。但不是第一行。
  • 你提供的额外空间 dealName.text = "一杯咖啡和 A asdf asd asdf adsf ads fad" 它应该是 dealName.text = "Cup of Coffee with A asdf asd asdf adsf ads fad" .

标签: ios iphone ios8 uilabel


【解决方案1】:

试试这个可能是在字符之前有一个空格,这将删除这个..

NSString *trimmed = [yourstring stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

yourlable.text = trimmed;

另外看看你是否从这里设置属性段落间距..

【讨论】:

  • 我只使用纯文本。
  • 试试修剪功能...可能对你有帮助
猜你喜欢
  • 2014-04-17
  • 1970-01-01
  • 2013-10-08
  • 2018-12-04
  • 1970-01-01
  • 2014-08-07
  • 2018-12-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多