工作中有时会碰到如图所示的需求,timeLabel
在不断更新时间过程中,导致左侧的button
也在不断晃动,给用户的体验很差
怎么解决呢?
将右侧的timeLabel
字体设置为等宽字体,即可解决
let baseFont = UIFont.systemFont(ofSize: 13)
let descriptor = baseFont.fontDescriptor.addingAttributes([
.featureSettings: [[
UIFontDescriptor.FeatureKey.featureIdentifier: kNumberSpacingType,
UIFontDescriptor.FeatureKey.typeIdentifier: kMonospacedNumbersSelector
]]
])
timeLabel.font = UIFont(descriptor: descriptor, size: 13)