我遇到了同样的问题。 @KenThomases 回答有效。这是 Swift 版本:
// replace whatever font your using with this font instead to stop the shaking
UIFont.monospacedDigitSystemFont(ofSize: 19, weight: UIFont.Weight.regular)
即:
yourLabel.font = UIFont.monospacedDigitSystemFont(ofSize: 19, weight: UIFont.Weight.regular)
仅供参考,还有其他UIFont.Weight 权重:
.black、.bold、.heavy、.light、.medium、.regular、.semibold、.thin、.ultraLight
According to this other answer 以下字体是系统生成的字体,也是等宽,因此它们也不会晃动:
快递
Courier-Bold
Courier-BoldOblique
Courier-Oblique
CourierNewPS-BoldItalicMT
CourierNewPS-BoldMT
CourierNewPS-ItalicMT
CourierNewPSMT
Menlo-Bold
Menlo-BoldItalic
Menlo-Italic
Menlo-Regular
即:
// no shaking
yourLabel.font = UIFont(name: "Menlo-Regular", size: 19)
如果您只使用数字,则 HelveticaNeue 也是 等宽 并且不会抖动,但值得怀疑。使用此字体前请阅读comments below this answer。
即:
// no shaking but apparently you can only use numbers not letters
yourLabel.font = UIFont(name: "HelveticaNeue", size: 19)