简体   繁体   English

UILabel中心对齐问题

[英]UILabel center align issue

I have a strange issue with UILabel. 我对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. 所有值都在UILabel中以中心对齐方式显示。

The issue is when we go from 2 digits to 1 digit, the text is no longer center aligned. 问题是当我们从2位数字变为1位数字时,文本不再居中对齐。

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选择器...

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

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