基于Objective-C的iOS霓虹灯程序
2015-11-14 16:44
309 查看
霓虹灯
基于OC实现的霓虹灯效果,看着有点刺眼。。。不过很好玩。效果图:
你需要做的东西,就是用Xcode新建一个iOS工程,然后将下面代码敲上就可以实现。
代码如下:
UIView *yellow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 600)]; yellow.backgroundColor = [UIColor yellowColor]; yellow.center = CGPointMake((self.window.frame.size.width) / 2, (self.window.frame.size.height) / 2); yellow.tag = 1; [self.window addSubview:yellow]; [yellow release]; UIView *red = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 500)]; red.backgroundColor = [UIColor redColor]; red.center = CGPointMake((self.window.frame.size.width) / 2, (self.window.frame.size.height) / 2); red.tag = 2; [self.window addSubview:red]; [red release]; UIView *blue = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 225, 400)]; blue.backgroundColor = [UIColor blueColor]; blue.center = CGPointMake((self.window.frame.size.width) / 2, (self.window.frame.size.height) / 2); blue.tag = 3; [self.window addSubview:blue]; [blue release]; UIView *green = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 300)]; green.backgroundColor = [UIColor greenColor]; green.center = CGPointMake((self.window.frame.size.width) / 2, (self.window.frame.size.height) / 2); green.tag = 4; [self.window addSubview:green]; [green release]; UIView *gray = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 75, 200)]; gray.backgroundColor = [UIColor grayColor]; gray.center = CGPointMake((self.window.frame.size.width) / 2, (self.window.frame.size.height) / 2); gray.tag = 5; [self.window addSubview:gray]; [gray release]; self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(change) userInfo:nil repeats:YES];
下面是一个方法:
- (void)change { UIView *yellow = [self.window viewWithTag:1]; UIView *red = [self.window viewWithTag:2]; UIView *blue = [self.window viewWithTag:3]; UIView *green = [self.window viewWithTag:4]; UIView *gray = [self.window viewWithTag:5]; UIView *temp = [[UIView alloc] init]; temp.backgroundColor = yellow.backgroundColor; yellow.backgroundColor = red.backgroundColor; red.backgroundColor = blue.backgroundColor; blue.backgroundColor = green.backgroundColor; green.backgroundColor = gray.backgroundColor; gray.backgroundColor = temp.backgroundColor; }
应该就是这些了,基本的小东西,挺好玩的。
相关文章推荐
- ios面向切面AOP(上) Objective-c版本
- 【Java相关】Java的Object类
- Objective-C多态,动态类型识别,动态绑定
- Objective-C 实例方法可见度,方法
- Objective-C中类属性的 copy, retain, assign , readonly , readwrite, nonatomic区别
- 在项目中同时使用Objective-C和Swift
- Objective-c:集合类型
- android studio + opencv开发,objectMatch摄像头实时处理
- Object公用方法
- CriticalFinalizerObject的作用
- Objective-C中的继承与多态, Category, Extension
- Objective-C 中protocol(协议)及delegate(委托、代理)
- Objective-c Category(类别)
- Objective-c 访问控制
- Objective-c 类的继承 方法重写 方法重载
- Objective-c 协议(protocol)
- Linq To Objective-C
- Objective-c @property和@Synthesize
- Objective-c 数据类型
- Objective-c 方法的调用