简体   繁体   中英

UILabel center align issue

I have a strange issue with UILabel.

I have a countdown module in my app that displays the days/hours/minutes/secs to a particular date.

All of the values are displayed in UILabels with center alignment.

The issue is when we go from 2 digits to 1 digit, the text is no longer center aligned.

I put the following code in the method that is called each second to try and resolve this, but no luck:

 secondLabel.textAlignment = UITextAlignmentCenter;
 secondLabel.baselineAdjustment =  UIBaselineAdjustmentAlignCenters;
 secondLabel.text = [NSString stringWithFormat:@"%2d", components.second];

Do I have redraw the label each time I put the number in there?

Thanks for your time.

您可以在stringWithFormat:使用@"%02i"代替@"%2d" stringWithFormat: NSString选择器...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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