Mani
Mani

Reputation: 17585

UILabel Vertical align missing space

I've used UILabel for showing text with vertical alignment. I'm showing text as character by character with vertical alignment. Actually It's an moving text by alignment with CABasicAnimation. But my problem here is

  1. Each line should show one character, but when I try stretch label width to show single character, Some character is wiped partially. see screen shot of xib(sample with small text).. Or try to extend frame size, some row show single character and some shows double character.
  2. Space is missing between words. see screenshot.

How can I fix it with my xib? Answer also acceptable with programmatically.

enter image description here

Note: Text used in this example "Some text with long".

Upvotes: 2

Views: 218

Answers (1)

Mika
Mika

Reputation: 5845

You don't need vertical align. Just make the UILabel wider and input a \n after every character of the string.

        NSString *longString = @"This is a very very long string";

        NSString *labelString = @"";

        self.label.text = labelString;
        self.label.numberOfLines = 500; //just put a big number or calculate something

        for (int n=longString.length - 1; n > -1; --n) {

            labelString = [NSString stringWithFormat:@"%@\n%@", [longString substringWithRange:NSMakeRange(n, 1)], labelString];

                self.label.text = labelString;

        }

Upvotes: 1

Related Questions