标签:uicolor nsarray alloc 方框赛跑 跑马灯
/*
代码一: 霓虹灯(跑马灯)
*/
NSArray *colorArray = [[[NSArray alloc] initWithObjects:[UIColor redColor], [UIColor orangeColor], [UIColor yellowColor], [UIColor greenColor], [UIColor cyanColor], [UIColor blueColor], [UIColor purpleColor], nil] autorelease];
CGFloat mulValue = [[UIScreen mainScreen] bounds].size.width / 7 ;
for (int i = 0, j = 0; i < 7; i++,j++) {
UIView *i = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width - (j * mulValue), [[UIScreen mainScreen] bounds].size.height - (j * mulValue))] ;
i.backgroundColor = [colorArray objectAtIndex:j];
i.tag = j + 1 ;
i.center = self.window.center ;
[self.window insertSubview:i atIndex:j] ;
[i release];
}
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(run) userInfo:nil repeats:YES] ;
return YES;
}
- (void)run {
UIColor *acolor = [self.window viewWithTag:7].backgroundColor;
for (int i = 7; i >= 1; i--) {
if (i > 1) {
[self.window viewWithTag:i].backgroundColor = [self.window viewWithTag:(i - 1)].backgroundColor;
}
else{
[self.window viewWithTag:i].backgroundColor = acolor;
}
}
}
NSArray *colors = @[[UIColor redColor], [UIColor orangeColor], [UIColor yellowColor], [UIColor greenColor], [UIColor cyanColor], [UIColor blueColor], [UIColor purpleColor]] ;
for (int i = 0; i < colors.count; i++) {
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.window.bounds.size.width - i * 60, self.window.bounds.size.height - i * 60)] ;
aView.center = self.window.center ;
aView.backgroundColor = colors[i] ;
[self.window addSubview:aView] ;
[aView release] ;
}
/*
代码二: 霓虹灯(跑马灯)
*/
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(_changBackgroundColor:) userInfo:[self.window subviews].lastObject repeats:YES] ;
return YES;
}
- (void)_changBackgroundColor:(NSTimer *)sender {
UIView *currentView = [sender userInfo] ;
//暂存当前视图的颜色.
UIColor *tempColor = currentView.backgroundColor ;
//获取当前视图在子视图数组中的下标
NSInteger currentIndex = [self.window.subviews indexOfObject:currentView] ;
for (NSInteger i = currentIndex - 1; i >= 0; i--) {
UIView *superView = self.window.subviews[i] ;
currentView.backgroundColor = superView.backgroundColor ;
currentView = superView ;
}
currentView.backgroundColor = tempColor ;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:uicolor nsarray alloc 方框赛跑 跑马灯
原文地址:http://blog.csdn.net/zhengang007/article/details/46873081