简体   繁体   English

停止带有更改数字的标签中的文本,使其无法在快速IOS中更改宽度

[英]Stop text in a label with changing numbers from changing width in swift IOS

How do i stop text in a label from moving/changing size (being dynamic) when it has numbers that are changing every second. 当标签中的数字每秒变化时,如何阻止标签中的文本移动/更改大小(动态)。

var duration = //user input
func counting() {
    label.text = "\(duration)"
    if duration > 0 {
        duration -= 1
    } else if duration == 0 {
        //stop
}

The functions updates itself every second. 该功能每秒更新一次。

I have an label that have numbers counting down every second, but when it changes numbers the width changes to depending on how big the number is. 我有一个标签,它的数字每秒都在计数,但是当数字改变时,宽度会根据数字的大小而变化。 How do i stop this and give every letter/number the same width. 我该如何停止,并给每个字母/数字相同的宽度。 So i want an "1" to take as much space as an "5". 因此,我希望“ 1”占用的空间与“ 5”一样大。 I am not talking about the space between (margin) but rather the space inside (item/letter/number size). 我不是在谈论(边距) 之间的空间而是在里面(项目/字母/数字大小)的空间。

Label text taking more space then if it had been 4:11 标签文本比4:11占用更多空间

Label text taking less space then if it had been 3:56 标签文本所占空间要小于3:56

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM