Dev*_*iOS 1 iphone uilabel ios
在UILabel中,您是否可以显示一个字符串,以便逐个字符填写?例如,如果标签文本是"IPHONE",我想显示"I",然后是"IP",然后是"IPH",一直显示"IPHONE".
我怎么能以这种方式显示标签?
小智 7
所以你想显示一个字符串的第一个字母,然后在一段时间之后显示它的第二个字母等.解决方案:使用定时调用方法的定时器; 该方法将适当地设置文本:
NSString *theTextToDisplay = @"Hello world!";
[NSTimer scheduledTimerWithTimeInterval:0.33
target:self
selector:@selector(timerShoot:)
userInfo:nil
repeats:YES];
- (void)timerShoot:(NSTimer *)tmr
{
static int pos = 1;
theUILabel.text = [theTextToDisplay substringToIndex:pos];
if (++pos > theTextToDisplay.length) {
[tmr invalidate];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
585 次 |
| 最近记录: |