ColourClock 将时间值转换成背景色
来源:互联网 发布:如何创建网络软件公司 编辑:程序博客网 时间:2024/06/05 11:26
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 = 0, ClockTypeHex = 1, ClockTypeRGB = 2};@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 > 200 && minFloat > 200 && secFloat > 200) { 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
0 0
- ColourClock 将时间值转换成背景色
- vs背景色值
- 将空间设为背景色
- 想要将UIButton设置背景色
- 将页面背景色改为红色
- Eclipse修改背景色值
- 背景色
- 背景色
- 将桌面图标名字背景色设置为无色
- 将位图的背景色置为透明
- 将png图片背景色置为透明
- 汇编实验 固定时间改变背景色及字符位置
- winform 控件背景色设置成透明
- 【myeclipse】修改成舒服的背景色
- 改变视图背景色的alpha值
- 保护眼睛的背景色值
- AngularJs点击状态值改变背景色
- POI获取excel单元格背景色转换为awt.Color
- More is better
- 基于SSL验证的Apache CXF客户端设计总结
- ClockView 时钟
- Apache服务器开启Gzip压缩
- mutex 例子
- ColourClock 将时间值转换成背景色
- C++封装epoll
- Android root 详解
- 利用友元函数实现对运算符的重载
- SFRoundProgressCounterView 带有进度显示的倒计时视图
- UNIX I/O摘要
- Jackson 框架,轻易转换JSON
- Installing the JDK with JAVA
- RTX_Config.c 宏定义详解