Question

I recently added a method to the object that takes care of scoring to a game I'm working on to return a string using NSNumberFormatter. I've just received a score of 163,930,640, and it is displayed this way in one place. But in another place, on a text label, it is displayed as 163,930,6.... I'm pretty sure all digits were displayed during active game play, but it switched to having an elipsis when it stopped being updated. Here is how I create the label:

self.scoreLabel = [[UILabel alloc] init];
self.scoreLabel.hidden = YES;
self.scoreLabel.text = @"0";
self.scoreLabel.frame = [self scoreFrame];
self.scoreLabel.textAlignment = NSTextAlignmentCenter;
self.scoreLabel.backgroundColor = [UIColor clearColor];
self.scoreLabel.font = [UIFont fontWithName:@"Marker Felt" size:36.0];
[self.scoreLabel setTextColor:[UIColor greenColor]];
[self.solutionBackgroundView addSubview:self.scoreLabel];

Could the problem be that the frame (set to 200 in the method not shown) is too small? I could change scoreFrame to initialize with a bigger frame, but I don't know what a maximum value would be, so I don't know what an appropriate size would be.

How would I size it appropriately to accommodate an unknown size? The score is updated 10 times a second, so I'm not sure using sizeToFit would be the right solution. I guess since I'm using textAlignmentCenter, and the label is centered where placed, I could just increase the size. On the other hand, I will be adding a feature to move the label to a space that is more restrictive. In any case, what I really want to know is what is triggering the elipsis.

The format I'm using is NSNumberFormatterDecimalStyle.

Was it helpful?

Solution

This is a UILabel lineBreakMode issue rather than an NSNumberFormatter issue. The text is being truncated because your label is not large enough to display the whole text. Either make your label larger or the font smaller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top