简体   繁体   中英

How to get the same character spacing for two UILabel items

http://home.astound.net/~puzzleblog/uploaded_images/calculator87355.gif

I am creating a calculator; for that I have taken the font type as "DBLCDTempBlack". It is working properly. In the image digits in a label are running on top of another label, and the bottom label has text "888888888" and so on to get an effect of faded light. So to get this effect, we need to have two labels on top of one another. When I am trying to give "1" continuously to the top label, it is not aligning with the digits which are at the back.

Digits 2-9,0 are generally made up of 8 in this font type so they are aligning. But when I am giving "1", character spacing is getting disturbed.

Edit the font so that 1 is the same width as the other digits, as it should be.

I wrote a little method that makes the spacing correct for having 1's in there. I don't know if this is the best way, but it turns out if you add a space before a 1, unless it's the first character in the string, the spacing is perfect.

- (NSMutableString *)stringForDigitalDisplayFromString:(NSString *)string {

    NSMutableString *formattedString = [[NSMutableString alloc] initWithCapacity:10];

    for (int i = 0; i < [string length]; i++) {
        char character = [string characterAtIndex:i];
        //if we have a 1 and it is not the first digit
        if (character == '1' && i != 0) {
            [formattedString appendString:[NSString stringWithFormat:@" %c",character]];
        }
        else {
            [formattedString appendString:[NSString stringWithFormat: @"%c",character]];
        }
    }

    return formattedString;
}

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