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 将时间值转换成背景色的更多相关文章

  1. ios 把毫秒值转换成日期 NSDate

    ios 把毫秒值转换成日期 (比较好用) 1343359790000 这是毫秒值------最佳解决方案-------------------- long long time=134335979000 ...

  2. Web API-如何将Controller的返回值转换成HTTP response消息

    https://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization https://co ...

  3. sql 在将 nvarchar 值 转换成数据类型 int 时失败。

    假设有存储过程:proc_test2 create proc proc_test2 @Id int begin as declare @sql varchar(max) @sql = 'select ...

  4. json字符串转换成json对象,json对象转换成字符串,值转换成字符串,字符串转成值

    一.json相关概念 json,全称为javascript object notation,是一种轻量级的数据交互格式.采用完全独立于语言的文本格式,是一种理想的数据交换格式. 同时,json是jav ...

  5. Jquery把获取到的input值转换成json

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. SQL3120W 不能将xx的字段值转换成 INTEGER值

    一次用DB2 Load/Import导入数据时,报错,提示SQL3120W 不能将xx的字段值转换成 INTEGER值,但目标列不可为空.未装入该行. 目标表: CREATE TABLE TEST( ...

  7. c# 科学计数法值转换成正常值,返回字符串

    /// <summary> /// 科学计数法值转换成正常值 /// </summary> /// <param name="value">&l ...

  8. 将数据库中的内容展示出来并将某些value值转换成汉字

    1.将数据库中的内容展示出来 前台代码未做改变,刚开始未显示的原因是因为 data-field 跟数据库不一样data-field 需要跟数据库中的一样才可以 2.将某些value值转换成汉字 在li ...

  9. sql server like 在将值转换成数据类型int失败

    select * from table where title like '%'?'%'; 采用? 传参会报错:sql server like 在将值转换成数据类型int失败 select * fro ...

随机推荐

  1. scala学习6--collection

     list的下标访问 var t = List(1,2,3,5,5) println(t(2)) map函数 println(t.map(a=> {print("***"+a ...

  2. 洛谷P2692 覆盖 题解

    题目传送门 这道题一开始想使用二维的bool型数组来存,最后统计.但看到数据范围... 所以就改用两个bool型数组(一维),分别储存横.列,最后将横.列面积求出来,再减去重复算的面积(横的个数*列的 ...

  3. JMeter -----设置代理抓取web的HTTPS请求,“您的连接不是私密链接”的处理方案

    出现如上截图的问题,已确定将网站的证书.jmeter的证书均安装完成,并未提示报错,但是在配置代理后,刷新网站抓取请求时总是提示如上报错 解决方案: 1.关闭电脑上的所有浏览器 2.打开“终端”运行: ...

  4. LoadRunner中Vugen-Recording Options选项卡介绍:

    LoadRunner中Vugen-Recording Options选项卡介绍:

  5. JAVAEE学习——hibernate03:多表操作详解、级联、关系维护和练习:添加联系人

    一.一对多|多对一 1.关系表达 表中的表达 实体中的表达 orm元数据中表达 一对多 <!-- 集合,一对多关系,在配置文件中配置 --> <!-- name属性:集合属性名 co ...

  6. Redis学习篇(九)之生存时间

    EXPIRE 设置生存时间,以秒为单位 #### EXPIREAT 设置生存时间,秒时间戳格式 #### PEXPIRE 设置生存时间,毫秒为单位 #### PEXPOREAT 设置生存时间,毫秒时间 ...

  7. 顺序存储线性表_ArrayList

    相信大家在日常开发过程中 List 应该使用的非常非常多,今天就来简单学习一下 List 的数据结构 顺序存储线性表. 一.什么是顺序存储线性表 顺序存储线性表是最基本.最简单.也是最常用的一种数据结 ...

  8. [BZOJ2594][WC2006]水管局长加强版(LCT+Kruskal)

    2594: [Wc2006]水管局长数据加强版 Time Limit: 25 Sec  Memory Limit: 128 MBSubmit: 4452  Solved: 1385[Submit][S ...

  9. HDU 6141 I am your Father!(最小树形图)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6141 [题目大意] 给出一个有向图,求1点为根的最小树形图使得第n个点的直接父亲编号最小 [题解] ...

  10. WEB架构师成长之路 一

    一 .你必须学习面向对象的基础知识 1.降低软件开发的复杂度 2.提高软件开发的效率 3.提高软件质量:可维护性,可扩展性,可重用性等. 提高软件质量:可维护性,可扩展性,可重用性等,再具体点,就是高 ...