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. Django之管理权限

    什么是权限: 谁对什么资源能做什么操作. 管理权限的实现有很多,这里实现一个最简单的管理权限的实现方式:rbac   ( role based access control ) 实现的一个基本思路: ...

  2. ubuntu安装Shutter截图工具以及设置系统快捷键

    一.安装截图工具 Shutter 1. 添加安装包软件源 sudo add-apt-repository ppa:shutter/ppa 2. 更新源并安装 shutter sudo apt-get ...

  3. 飘窗原生js效果

    css: .close { width: 30px; height: 20px; background: white; position: absolute; right: 0; top: 0; z- ...

  4. 服务管理(svcadm)

    svcs   正在运行的服务 svcs -a  正在运行和没运行的服务 svcs -D  此进程依赖的进程    svcs -D sendmail svcs -d  依赖于此进程的进程  svcs - ...

  5. Qt基础——让使用Designer创建的UI也能自动适应窗口大小

    原文请看:http://www.cnblogs.com/linmeng/archive/2012/07/05/2559259.html 我们知道,通过Qt的各种Layout可以实现控件的自动布局. 但 ...

  6. EOJ 3247 铁路修复计划

    二分,最小生成树. 二分一下$k$,然后每次算最小生成树验证即可,事实证明,$cmp$函数,参数用引用还是能提高效率的,不引用一直$TLE$,时限有点卡常. 然后错误的代码好像$AC$了啊,$L$和$ ...

  7. Mybatis使用入门

    一.Mybatis简介 1.传统JDBC的不足 我们首先看一下JDBC的一般操作流程.比如,我想从user表中获取根据name获取数据,下面是传统JDBC代码: package lkb.webchat ...

  8. Android 之JSON数据解析

    (以下基本都是郭霖大神<第一行代码>中的知识) JSON数据与xml相比,优势在于体积更小,传输所需的流量少.但是缺点也很明显,就是语义性较差. 下面是一组JSON格式的数据. [{&qu ...

  9. 实验吧 recursive write up

    这是一个python写的文件 推测是用Freeze打包 所以必有一个Py_FrozenMain函数 分析函数有两个变量PYTHONINSPECT”和“PYTHONUNBUFFERED”之后都会调用ge ...

  10. (转) redis的事务和watch

    redis的事务 严格意义来讲,redis的事务和我们理解的传统数据库(如mysql)的事务是不一样的. redis中的事务定义 Redis中的事务(transaction)是一组命令的集合. 事务同 ...