【问题标题】:UIButton with attributed text not respecting adjustsFontSizeToFitWidth带有属性文本的 UIButton 不尊重 adjustsFontSizeToFitWidth
【发布时间】:2016-09-10 23:59:28
【问题描述】:

关于为什么在 IB 上设置属性文本的 UIButton 不尊重 adjustsFontSizeToFitWidth 的任何想法。

 button.titleLabel?.numberOfLines = 3
 button.titleLabel?.adjustsFontSizeToFitWidth = true
 button.titleLabel?.lineBreakMode = .//tried all options here....
 button.titleLabel?.minimumScaleFactor = 0.2

【问题讨论】:

  • 你试过这个按钮吗?titleLabel?.lineBreakMode = NSLineBreakByClipping;
  • 你在哪里为按钮设置文本
  • 界面生成器。
  • 在帖子中查看图片。您确定第一行与您的 uibutton 成比例地“增长”吗?我没有得到同样的效果......
  • 我知道...我在问你是如何用 3 行写的

标签: ios uibutton swift2


【解决方案1】:

adjustsFontSizeToFitWidth 不适用于属性字符串,您必须自己手动设置适当的字体大小

【讨论】:

  • 这违背了在 IB 中包含任何属性文本的目的,不是吗?如果我手动设置文本...
  • 通过hit和trial增加ib中uibutton的宽度并调整你的属性字符串
  • 这有什么帮助?
  • @GeorgeAsda 我也遇到了同样的问题,有解决办法吗?
  • @Moondra 我还没找到。
猜你喜欢
  • 2016-09-26
  • 1970-01-01
  • 2011-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-23
  • 2021-11-12
相关资源
最近更新 更多