2014-12-18 8 views
4

저는 UILabel이 티커처럼 작동하므로 매 0.09 초마다 텍스트가 변경됩니다. 그러나 레이블 끝에 공백이 오면 트리밍되므로 시세가 지연되는 것처럼 보입니다. 정말 도움이 필요UILabel의 끝에 공간을 트리밍하지 않으려면 어떻게합니까?

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; 

:

[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]; 

너지 티커 방법은 다음을 수행합니다

여기에 코드입니다. 이 문제를 어떻게 해결할 수 있습니까? 그런데 UILabel의 본문은 아랍어로되어 있습니다.

+0

0.09 밀리 초입니까? 90 밀리 초라고 가정합니다. – rdelmar

+0

다듬은 것은 무엇을 의미합니까? 레이블에 배경색이있어 공간이 떨어지는 것이 확실합니까? 크기가 다듬어 지거나 다른 것이 있습니까? –

+0

@rdelmar yeah i mean 0.09 seconds – Eddy

답변

5

해킹이 약간 있지만 한 가지 해결책은 라벨에 속성이 지정된 문자열을 사용하고 문자열 끝에 투명 기간 (".")을 포함하는 것입니다.

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; 
} 
+0

감사합니다 youuuuu :) – Eddy

+0

당신은 천재입니다. –