Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何阻止UILabel修剪末端的空间?_Ios_Uilabel_Arabic_Spaces_Trim - Fatal编程技术网

Ios 如何阻止UILabel修剪末端的空间?

Ios 如何阻止UILabel修剪末端的空间?,ios,uilabel,arabic,spaces,trim,Ios,Uilabel,Arabic,Spaces,Trim,我有一个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:[UIF

我有一个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];
微移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;

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

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

只需替换您的
轻推代码:
方法

- (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;
}

0.09毫秒,真的吗?我想你的意思是90毫秒。你说的修剪是什么意思?标签是否有一些背景颜色,以便清楚地显示空间是否被删除?是尺寸被修剪了还是其他什么?@rdelmar是的,我的意思是0.09秒你是个天才。你是个天才。