如何阻止UILabel在最后修剪空间?

Edd*_*ddy 4 spaces trim arabic uilabel ios

我有一个UILabel就像一个自动收报机所以每隔0.09秒就会改变文字,但是当标签末尾的空格被修剪时,它看起来就像是自动收报机了.

这是代码:

[self setTickerLabel: [ [UILabel alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40)]];


[self.tickerLabel setFont:[UIFont fontWithName:@"Courier" size:TICKER_FONT_SIZE]];

self.text =[NSString stringWithFormat:@"%@",self.result];


self.tickerLabel.textAlignment = NSTextAlignmentRight;

[self.tickerLabel setText:self.text];

[self.tickerLabel setLineBreakMode:NSLineBreakByWordWrapping];


[NSTimer scheduledTimerWithTimeInterval:TICKER_RATE target:self selector: @selector(nudgeTicker:) userInfo:nil repeats:YES];

[self.view addSubview:self.tickerLabel];
Run Code Online (Sandbox Code Playgroud)

轻推Ticker方法执行以下操作:

NSString* firstLetter = [self.text substringWithRange: NSMakeRange(0,1)];
NSString* remainder = [self.text substringWithRange:NSMakeRange(1,[self.text length]-1)];
self.text=[remainder stringByAppendingString: firstLetter];
self.tickerLabel.text=self.text;
Run Code Online (Sandbox Code Playgroud)

我真的需要一些帮助.我怎样才能解决这个问题?顺便说一句,UILabel的文字是阿拉伯语.

pic*_*ano 7

有点破解,但一种解决方案是在标签中使用属性字符串,并在字符串末尾包含透明句点(".").

只需替换您的nudgeTicker:方法.

- (void)nudgeTicker:(id)target {
    NSString* firstLetter = [self.text substringWithRange: NSMakeRange(0,1)];
    NSString* remainder = [self.text substringWithRange:NSMakeRange(1,[self.text length]-1)];
    self.text=[remainder stringByAppendingString: firstLetter];
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@.", self.text]];
    [string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,string.length-1)];
    [string addAttribute:NSForegroundColorAttributeName value:[UIColor clearColor] range:NSMakeRange(string.length-1,1)];
    self.tickerLabel.attributedText = string;
}
Run Code Online (Sandbox Code Playgroud)