如何更改Apple Watch标签的字体大小

11

我感到有点震惊,我甚至要问这个问题,但是如何改变Apple watch标签的文字大小呢?它不允许在Xcode UI中更改大小,我也无法通过编程实现,而不同的字体样式甚至无法改变大小。

2个回答

17

使用UI

要更改字体,您不能使用主模板(文本样式-正文)。您应将其更改为“系统”,然后尝试更改字体大小:

输入图像描述

输入图像描述

使用代码

lblSomething.setAttributedText(NSAttributedString(string: "Text Here", attributes: [NSFontAttributeName: UIFont.systemFontOfSize(20.0, weight: UIFontWeightBold)]))

注意事项

1- 请使用自己的字体大小,而不是20.0。

2- 你可以使用以下其中一个代替UIFontWeightBold

enter image description here

3- 请使用自己的文本内容,而不是“Text Here”。

4- 请使用自己的标签名称,而不是lblSomething


UIFontWeightBold etc. has been renamed to UIFont.Weight.bold or just .bold - John Morris
嗨,我正在寻找一种在不改变大小的情况下更改权重的方法,以便它可以适用于所有的 Apple Watch 大小。我在界面生成器中设置了大小。 - Kurt L.

4

您可以通过使用NSAttributedString编程实现此目的:

let font = UIFont.systemFontOfSize(32.0, weight: UIFontWeightMedium)
let attrStr = NSAttributedString(string: "Some String", attributes: [NSFontAttributeName: font])
label.setAttributedText(attrStr)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接