开发者

UILabel center align issue

开发者 https://www.devze.com 2023-04-02 17:10 出处:网络
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.

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 o开发者_如何学JAVAf 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.


You can use @"%02i" instead @"%2d" in the stringWithFormat: NSString selector...

0

精彩评论

暂无评论...
验证码 换一张
取 消