IOS入门——使用UIView简单实现霓虹灯(两种方法)
来源:互联网 发布:仿今日头条网站源码 编辑:程序博客网 时间:2024/06/16 14:30
方法一:简单实现四边框跑马灯
//// AppDelegate.m// Copyright © 2015年 Treney.com . All rights reserved.//#import "AppDelegate.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self.window makeKeyAndVisible]; colors = @[[UIColor redColor],[UIColor blueColor],[UIColor yellowColor],[UIColor orangeColor],[UIColor greenColor],[UIColor grayColor],[UIColor blackColor]]; for (int i=0; i<7; i++) { UIView *view = [[UIView alloc]initWithFrame:CGRectMake(i*50, 50, 50, 50)]; UIView *view_1 = [[UIView alloc]initWithFrame:CGRectMake(0, i*50+50, 50, 50)]; UIView *view_2 = [[UIView alloc]initWithFrame:CGRectMake(i*50, 400, 50, 50)]; UIView *view_3 = [[UIView alloc]initWithFrame:CGRectMake(270, i*50+50, 50, 50)]; view.tag = 100+i; view_1.tag=200+i; view_2.tag=300+i; view_3.tag=400+i; view.backgroundColor =colors[arc4random()%colors.count]; view_1.backgroundColor =colors[arc4random()%colors.count]; view_2.backgroundColor =colors[arc4random()%colors.count]; view_3.backgroundColor =colors[arc4random()%colors.count]; [self.window addSubview:view]; [self.window addSubview:view_1]; [self.window addSubview:view_2]; [self.window addSubview:view_3]; } [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(start) userInfo:nil repeats:YES]; return YES;}-(void)start{ UIColor *te = [self.window viewWithTag:100 ].backgroundColor;//查找tag为100的视图,操作te就是操作tag为100的视图,这里设置te是为了实现递进,先保存tag=100的视图的颜色,左后重新赋值给最后一个视图 UIColor *te_1 = [self.window viewWithTag:200 ].backgroundColor; UIColor *te_2 = [self.window viewWithTag:300 ].backgroundColor; UIColor *te_3 = [self.window viewWithTag:400 ].backgroundColor; for (int i = 0; i <6; i++) { [self.window viewWithTag:100 +i ].backgroundColor = [self.window viewWithTag:101 +i ].backgroundColor; [self.window viewWithTag:200 +i ].backgroundColor = [self.window viewWithTag:201 +i ].backgroundColor; [self.window viewWithTag:300 +i ].backgroundColor = [self.window viewWithTag:301 +i ].backgroundColor; [self.window viewWithTag:400 +i ].backgroundColor = [self.window viewWithTag:401 +i ].backgroundColor; } [self.window viewWithTag:106 ].backgroundColor = te; [self.window viewWithTag:206 ].backgroundColor = te_1; [self.window viewWithTag:306 ].backgroundColor = te_2; [self.window viewWithTag:406 ].backgroundColor = te_3;}
方法二:实现霓虹灯效果等闪烁
//// AppDelegate.m// 地方// Copyright © 2015年 Treney.com. All rights reserved.//#import "AppDelegate.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [self.window makeKeyAndVisible]; //定义颜色数组 NSMutableArray *arr = [NSMutableArray arrayWithObjects:[UIColor redColor], [UIColor yellowColor],[UIColor blueColor],[UIColor greenColor],[UIColor grayColor],[UIColor purpleColor],[UIColor orangeColor],nil]; //for循环 设定位置 颜色 for (int i = 0 ; i < 7; i++) { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(i * 20, i *20, 320 - 40 * i , 568 - i * 40)];//x y轴依次改变,宽高依次减小 xy越大 宽高越小 view.tag = 100 + i;//设置tag view.backgroundColor = arr[i];//设置视图颜色(从可变数组arr中读取) [self.window addSubview:view];//添加到主窗口 } [NSTimer scheduledTimerWithTimeInterval:0.23 target:self selector:@selector(time) userInfo:nil repeats:YES]; self.window.backgroundColor = [UIColor whiteColor]; return YES;}- (void)time{ UIColor *te = [self.window viewWithTag:100 ].backgroundColor;//查找tag为100的视图,操作te就是操作tag为100的视图,这里设置te是为了实现递进,先保存tag=100的视图的颜色,左后重新赋值给最后一个视图 for (int i = 0; i <6; i++) { [self.window viewWithTag:100 +i ].backgroundColor = [self.window viewWithTag:101 +i ].backgroundColor; } [self.window viewWithTag:106 ].backgroundColor = te;}
0 0
- IOS入门——使用UIView简单实现霓虹灯(两种方法)
- IOS开发入门基本知识——UIView和NSTimer形成的霓虹灯效果
- 两种方法实现UIView插入背景图片
- ajax的简单使用——get&post两种方法的实现(1)
- iOS 为UIView添加渐变色的两种方法
- iOS property两种实现方法区别的简单介绍
- 七彩霓虹灯可以实现两种效果(更新版本2)
- iOS UIView方法使用详情UIView : UIResponder
- 布局——霓虹灯布局的实现
- iOS设置圆形(圆角)UIView、UIButton的简单方法
- 使用FrameLayout实现霓虹灯效果
- IOS开发入门基本知识——实现小猫招呼UIView UILabel UIButton NSTimer层级关系
- IOS中UIView动画的简单实现
- 霓虹灯效果(UIView)
- 菜鸟初学android体验之——实现自定义简单标题栏的两种简单方法
- 创建UIView对象的两种方法
- 用简单UI控件实现霓虹灯
- iOS之UI编程--霓虹灯的实现
- JDK自带加密算法sha-1
- cocos2dx3.4开发环境搭建详解(2)
- 【Leetcode】之Longest Valid Parentheses
- 配给应用程序的内存太小,将导致内存不足
- dpi 、 dip 、分辨率、屏幕尺寸、px、density 关系以及换算
- IOS入门——使用UIView简单实现霓虹灯(两种方法)
- Caused by: java.sql.SQLException: The user specified as a definer ('eln'@'%') does not exist
- 使用Git命令把本地项目上传到GitHub托管
- hdu计算机学院大学生程序设计竞赛(2015’11)1003 玩骰子
- Android Jsoup解析HTML部署与使用
- Android开发总结笔记 Dialog(对话框) 1-1-19
- HTML基础笔记1
- 装饰者设计模式
- android getIdentifier获取资源ID用法