IOS-UI学习一,霓虹灯
来源:互联网 发布:js实现购物车 编辑:程序博客网 时间:2024/04/29 06:41
1.新建一个类HomeViewController.m继承于viewController,并且在AppDelegate.m文件中导入
#import "AppDelegate.h"
#import "HomeViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//声明
HomeViewController *homeVC = [HomeViewController new];
self.window.rootViewController = homeVC;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
2.在HomeViewController.m文件写代码
//霓虹灯
#import "HomeViewController.h"
@interface HomeViewController ()
//三个全局变量,可以在HomeViewController.m文件里面使用
{
UIView *view;
NSArray *neonLightColorArray;
NSTimer *timer;
}
@end
@implementation HomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
//屏幕大小
CGFloat screen_width = [[UIScreen mainScreen] bounds].size.width;
CGFloat screen_height = [[UIScreen mainScreen] bounds].size.height;
//设置背景颜色
UIView *backGroundView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
backGroundView.backgroundColor = [UIColor blackColor];
[self.view addSubview:backGroundView];
//霓虹灯大小
CGFloat x = (screen_width - 40)/7;
//创建霓虹灯
neonLightColorArray = [[NSArray alloc] initWithObjects:[UIColor redColor],[UIColor orangeColor],[UIColor yellowColor],[UIColor greenColor],[UIColor cyanColor],[UIColor blueColor],[UIColor purpleColor], nil];
for (int i = 0 ; i < 7 ; i++) {
view = [[UIView alloc] initWithFrame:CGRectMake(x/2+x*i, screen_height/8, x, x)];
view.backgroundColor = neonLightColorArray[i];
view.tag = 100+i;
[self.view addSubview:view];
}
//创建按钮(颜色从右到左改变颜色)
UIButton *leftToRightStratButton = [UIButton buttonWithType:UIButtonTypeSystem];
leftToRightStratButton.frame = CGRectMake(x/2, screen_height/4, 2*x, x);
leftToRightStratButton.backgroundColor = [UIColor whiteColor];
[leftToRightStratButton setTitle:@"从左到右" forState:0];
[leftToRightStratButton setTitleColor:[UIColor blackColor] forState:0];
[leftToRightStratButton addTarget:self action:@selector(leftToRightButtonAction:) forControlEvents:UIControlEventTouchUpInside];
leftToRightStratButton.layer.cornerRadius = 15;
[self.view addSubview:leftToRightStratButton];
//创建按钮(颜色从左到右改变)
UIButton *rightToLeftStartButton = [UIButton buttonWithType:UIButtonTypeSystem];
rightToLeftStartButton.frame = CGRectMake(5*x, screen_height/4, 2*x, x);
rightToLeftStartButton.backgroundColor = [UIColor whiteColor];
[rightToLeftStartButton setTitle:@"从右到左" forState:0];
[rightToLeftStartButton setTitleColor:[UIColor blackColor] forState:0];
[rightToLeftStartButton addTarget:self action:@selector(rightToLeftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
rightToLeftStartButton.layer.cornerRadius = 15;
[self.view addSubview:rightToLeftStartButton];
}
//从右到左按钮触发事件
-(void)rightToLeftButtonAction:(UIButton *)sender {
[timer invalidate];
timer = [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(rightToLeft) userInfo:nil repeats:YES];
}
//颜色从右到左改变
-(void)rightToLeft {
UIView *temp = [[UIView alloc] init];
int i = 100;
temp.backgroundColor = [self.view viewWithTag:100].backgroundColor;
for ( ; i < 106 ; i++) {
[self.view viewWithTag:i].backgroundColor = [self.view viewWithTag:1+i].backgroundColor;
}
[self.view viewWithTag:106].backgroundColor = temp.backgroundColor;
}
//从左到右按钮触发事件
-(void)leftToRightButtonAction:(UIButton *)sender {
[timer invalidate];
timer = [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(leftToRight) userInfo:nil repeats:YES];
}
//颜色从左到右改变
-(void)leftToRight {
UIView *temp = [[UIView alloc] init];
int i = 106;
temp.backgroundColor = [self.view viewWithTag:106].backgroundColor;
for ( ; i >99 ; i--) {
[self.view viewWithTag:i].backgroundColor = [self.view viewWithTag:i-1].backgroundColor;
}
[self.view viewWithTag:100].backgroundColor = temp.backgroundColor;
}
- IOS-UI学习一,霓虹灯
- iOS之UI编程--霓虹灯的实现
- iOS之UI编程--霓虹灯的实现
- ui 霓虹灯
- UI创建霓虹灯视图
- iOS UI控件学习---swift(一)
- IOS 霓虹灯效果
- IOS 霓虹灯效果(oc)
- UI中霓虹灯效果代码
- 实现霓虹灯闪烁效果(UI)
- 用iOS的UI知识编出霓虹灯效果(经典小题)
- iOS - UI: 动画汇总一(学习日记)
- iOS UI学习笔记(一)UIView基础
- 用简单UI控件实现霓虹灯
- 霓虹灯
- 霓虹灯
- 霓虹灯
- 霓虹灯
- 辩证法
- ora 06413 连接未打开
- 各种字符串Hash函数比较
- C/C++中的内存对齐
- 《重读抗战》
- IOS-UI学习一,霓虹灯
- 匈牙利命名法
- LeetCode Rotate List
- 第一个留言板界面
- 每个程序员需掌握的20个代码命名小贴士
- 第三周项目一——三角形类1
- selenium win7+selenium2.0+python环境搭建
- python网络爬虫,抓取网页图片
- RDO安装Openstack ICEHOUSE