我正在开发一个 iphone 应用程序并且有一个 UILabel 我想每 30 秒更改一次但保持相同的帧以便一个消失然后显示另一个。使用此代码一次绘制所有标签,然后终止。我也在使用ARC。
-(void)viewDidLoad
{
[super viewDidLoad];
label1= [[UILabel alloc] initWithFrame:CGRectMake(80, 200, 100, 50)];
label1.text=@"test";
label1.backgroundColor= [UIColor clearColor];
[self.view addSubview:label1];
label2= [[UILabel alloc] initWithFrame:CGRectMake(80, 200, 100, 50)];
label2.text=@"change";
label2.backgroundColor= [UIColor clearColor];
[self.view addSubview:label2];
...
warmup = [[NSMutableArray alloc] initWithObjects:label1,label2,label3, nil];
timer=[NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(rotatewarmup )userInfo:nil repeats:YES];
}
-(void)rotatewarmup
{
for (NSUInteger i = 0; i < [warmup count]; i++) {
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(80, 200, 100, 50)];
label.textColor=[UIColor whiteColor];
label.text =[warmup objectAtIndex:i];
NSString*string=[[NSString alloc] initWithFormat:@"%i"];
[label setText:string];
[self.view addSubview: label];
}