###### In iOS App, countdown often appears, but also found a small problem, that is, the countdown copy will shake left and right. Even if I put a zero in the last one digit, and I get to two digits, I’m still going to wobble from side to side. The specific effect is shown as follows:

Optimization of a:

I think this changes the text alignment to center instead of left. That way it won’t sway from side to side. _timeLabel.textAlignment = NSTextAlignmentCenter; But reality is harsh, a little better, but still no.

Optimization of 2:

Continue to center the text and set the width of the UILabel slightly wider than the countdown text. Calculate the text width of the timeLabel and add a little offset.

    [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(self.timeLabel.intrinsicContentSize.width + 5);
    }];
Copy the code

Reality or malicious face ( ̄ epsilon (#  ̄) being ╰ ╮ ( ̄ del  ̄ / / /) ~ (≧ del ≦) / ~ la la la, good a little bit, but still shaking..

Solution:

It would be useless to adjust the controls. The problem probably isn’t with the controls. Check the countdown. Later, it was found that the digital text width of the countdown text was inconsistent, causing the whole text to sway from side to side. Font-family: “.sfuitext “; font-family: “.sfuitext “;

Setting the font of the control text is perfect!!

Timelabel. font = [UIFont systemFontOfSize:13.0f]; _timelabel. font = [UIFont fontWithName:@"Helvetica Neue" size:13];
Copy the code

The effect is shown below:

References:

StringsTextFonts