[翻译] ColourClock 将时间值转换成背景色
ColourClock 将时间值转换成背景色

https://github.com/bennyguitar/ColourClock
This project converts Time to Hex/RGB, and is quite beautiful to look at. This was HEAVILY inspired byhttp://thecolourclock.co.uk and really, all credit goes to them.
这个工程是用来把时间值转换为Hex/RGB值的,看起来非常漂亮。灵感来自于这个网站 http://thecolourclock.co.uk

使用思路:
将一个要根据时间改变颜色View中layer的backgroundcolor赋值即可动态改变颜色。
附录:
ViewController.h
//
// ViewController.h
// ColourClock
//
// Created by Ben Gordon on 12/20/12.
// Copyright (c) 2012 Ben Gordon. All rights reserved.
// #import <UIKit/UIKit.h> enum ClockType {
ClockTypeMilitary = ,
ClockTypeHex = ,
ClockTypeRGB =
}; @interface ViewController : UIViewController { __weak IBOutlet UILabel *timeLabel;
__weak IBOutlet UILabel *appearanceType; enum ClockType currentType;
} - (IBAction)changeClockType:(id)sender; @end
ViewController.m
//
// ViewController.m
// ColourClock
//
// Created by Ben Gordon on 12/20/12.
// Copyright (c) 2012 Ben Gordon. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController #pragma mark - View Lifecycle - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. currentType = ClockTypeMilitary;
[self changeColor]; } - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - Change Colors -(void)changeColor {
// Set up date formatters for hour, min, seconds.
// Then create strings from the current date.
NSDateFormatter *formatHour = [[NSDateFormatter alloc] init];
NSDateFormatter *formatMin = [[NSDateFormatter alloc] init];
NSDateFormatter *formatSec = [[NSDateFormatter alloc] init];
[formatHour setDateFormat:@"HH"];
[formatMin setDateFormat:@"mm"];
[formatSec setDateFormat:@"ss"];
NSString *hour = [formatHour stringFromDate:[NSDate date]];
NSString *minute = [formatMin stringFromDate:[NSDate date]];
NSString *second = [formatSec stringFromDate:[NSDate date]]; // Create floats of the time value.
float hourFloat = [hour floatValue] * 255.0f / 23.0f;
float minFloat = [minute floatValue] * 255.0f / 59.0f;
float secFloat = [second floatValue] * 255.0f / 59.0f; // Create unsigned ints for Hex translation
int32_t hourint = hourFloat + 0.5;
int32_t minint = minFloat + 0.5;
int32_t secint = secFloat + 0.5; // Change text color so it's readable.
if (hourFloat > && minFloat > && secFloat > ) {
timeLabel.textColor = [UIColor darkGrayColor];
appearanceType.textColor = [UIColor darkGrayColor];
}
else {
timeLabel.textColor = [UIColor whiteColor];
appearanceType.textColor = [UIColor whiteColor];
} // Set Labels
if (currentType == ClockTypeMilitary) {
appearanceType.text = @"MILITARY TIME";
timeLabel.text = [NSString stringWithFormat:@"%@:%@:%@", hour, minute, second];
}
else if (currentType == ClockTypeHex) {
appearanceType.text = @"HEX COLOR CODE";
timeLabel.text = [NSString stringWithFormat:@"#%02X%02X%02X",hourint,minint,secint];
}
else {
appearanceType.text = @"RGB VALUES";
timeLabel.text = [NSString stringWithFormat:@"%.0f:%.0f:%.0f", hourFloat, minFloat, secFloat];
} // Finally, change image to the right color
self.view.backgroundColor = [UIColor colorWithRed:(hourFloat/255.0f) green:(minFloat/255.0f) blue:(secFloat/255.0f) alpha:1.0]; // And do it all over again, every .05 seconds so it's more accurate
[self performSelector:@selector(changeColor) withObject:nil afterDelay:0.05];
} #pragma mark - Change Clock Type - (IBAction)changeClockType:(id)sender {
currentType++; if (currentType > ClockTypeRGB) {
currentType = ClockTypeMilitary;
}
} @end
[翻译] ColourClock 将时间值转换成背景色的更多相关文章
- ios 把毫秒值转换成日期 NSDate
ios 把毫秒值转换成日期 (比较好用) 1343359790000 这是毫秒值------最佳解决方案-------------------- long long time=134335979000 ...
- Web API-如何将Controller的返回值转换成HTTP response消息
https://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization https://co ...
- sql 在将 nvarchar 值 转换成数据类型 int 时失败。
假设有存储过程:proc_test2 create proc proc_test2 @Id int begin as declare @sql varchar(max) @sql = 'select ...
- json字符串转换成json对象,json对象转换成字符串,值转换成字符串,字符串转成值
一.json相关概念 json,全称为javascript object notation,是一种轻量级的数据交互格式.采用完全独立于语言的文本格式,是一种理想的数据交换格式. 同时,json是jav ...
- Jquery把获取到的input值转换成json
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- SQL3120W 不能将xx的字段值转换成 INTEGER值
一次用DB2 Load/Import导入数据时,报错,提示SQL3120W 不能将xx的字段值转换成 INTEGER值,但目标列不可为空.未装入该行. 目标表: CREATE TABLE TEST( ...
- c# 科学计数法值转换成正常值,返回字符串
/// <summary> /// 科学计数法值转换成正常值 /// </summary> /// <param name="value">&l ...
- 将数据库中的内容展示出来并将某些value值转换成汉字
1.将数据库中的内容展示出来 前台代码未做改变,刚开始未显示的原因是因为 data-field 跟数据库不一样data-field 需要跟数据库中的一样才可以 2.将某些value值转换成汉字 在li ...
- sql server like 在将值转换成数据类型int失败
select * from table where title like '%'?'%'; 采用? 传参会报错:sql server like 在将值转换成数据类型int失败 select * fro ...
随机推荐
- 如何去除decimal后面的零?
如何去除decimal后面的零? 1.260000m.ToString("G29") 不显示科学记数法? decimal.Parse("0.0000001",S ...
- postgresql 数据导入导出
[转] 分类: postgresql2013-06-09 10:21 2486人阅读 评论(0) 收藏 举报 一.导出数据库及具体表 1.导出数据库:方式一:pg_dump -U postgres ...
- 用js 的for循环打印三角形,提取水仙花数,求本月多少天
第一题:用for循环打印三角形 //第一个 for(var x = 1;x <= 4;x++){ //控制行数 :由 1 到 4 for(var y = 1;y <= x;y++){ // ...
- 2019.2.25 模拟赛T1【集训队作业2018】小Z的礼物
T1: [集训队作业2018]小Z的礼物 我们发现我们要求的是覆盖所有集合里的元素的期望时间. 设\(t_{i,j}\)表示第一次覆盖第i行第j列的格子的时间,我们要求的是\(max\{ALL\}\) ...
- poj1915 Knight Moves(BFS)
题目链接 http://poj.org/problem?id=1915 题意 输入正方形棋盘的边长.起点和终点的位置,给定棋子的走法,输出最少经过多少步可以从起点走到终点. 思路 经典bfs题目. 代 ...
- vue开发关于微信授权登录以及路由mode模式(Hash|History)和手机平台(andriod|IOS)不得不说的故事
引用链接: https://segmentfault.com/a/1190000010753247?utm_source=tuicool&utm_medium=referral
- windows关闭aslr办法
关闭aslr方便调试分析. 转:https://www.52pojie.cn/thread-377450-1-1.html windows关闭aslr办法 如 @Hmily 前辈所说, Window ...
- COMP COMP-3
Comp (Computational) Comp (with no suffix) leaves the choice of the data type to the compiler writer ...
- 2017广东工业大学程序设计竞赛决赛--Problem B: 占点游戏
Description 众所周知的是,TMK特别容易迟到,终于在TMK某次又迟到了之后,Maple怒了,Maple大喊一声:"我要跟你决一死战!"然后Maple就跟TMK玩起了一个 ...
- python中对list去重的多种方法
今天遇到一个问题,用了 itertools.groupby 这个函数.不过这个东西最终还是没用上. 问题就是对一个list中的新闻id进行去重,去重之后要保证顺序不变. 直观方法 最简单的思路就是: ...