【问题标题】:Dynamicaly scale the fonts in UIButton动态缩放 UIButton 中的字体
【发布时间】:2018-03-11 17:32:41
【问题描述】:

刚刚更新了我之前的问题 How to scale the fonts in a Button 仍然没有答案 问题描述 - 我从 main.storyboard 界面创建了一些 UIButton。按钮有一些标题。当我使用约束时,按钮大小会随着我更改设备屏幕大小而增加。同时,标题字体保持不变,所以我有带有非常小的标题的大按钮。当我使用带有小屏幕的设备作为 iPhone4 时,标题会从按钮边缘消失。 我试过了

@IBAction func touchDigit(_ sender: UIButton) {
        sender.titleLabel?.minimumScaleFactor = 0.5;
        sender.titleLabel?.numberOfLines = 0
        sender.titleLabel?.adjustsFontSizeToFitWidth = true

我使用可检查变量为按钮创建了类

@IBInspectable var adjustFontSize : Bool {
set { titleLabel?.adjustsFontForContentSizeCategory = newValue }
get { return titleLabel!.adjustsFontForContentSizeCategory  }
   }

没有效果。 UILabel 有自动调整字体复选框。 UIButton 没有。 我相信每个人都有这样的问题,解决方案似乎很简单。请帮忙找一下!

【问题讨论】:

  • 您是否要让标题标签换行成多行以调整字体大小?
  • 它只是按钮上的一个符号。因为它的字体大小为 25,所以在 iPhone7 上看起来不错,在 12 英寸 iPad 上看起来很可怜​​
  • 嗯...一个符号?哪个符号?哪种字体?
  • 可以根据IB中的size类来设置按钮字体。单击字体旁边的 + 并为更大尺寸的类设置更大的字体。

标签: ios swift uibutton


【解决方案1】:

使用这个:

sender.titleLabel?.lineBreakMode = .byClipping

【讨论】:

  • 我在按钮上只有一个符号,所以我确定换行符不是这种情况
猜你喜欢
  • 2011-01-03
  • 1970-01-01
  • 1970-01-01
  • 2015-07-24
  • 2016-12-10
  • 1970-01-01
  • 2015-03-09
  • 1970-01-01
  • 2023-01-10
相关资源
最近更新 更多