zl程序教程

您现在的位置是:首页 >  其它

当前栏目

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

时间 翻译 转换成 背景色
2023-09-14 08:57:58 时间
// Created by Ben Gordon on 12/20/12. // Copyright (c) 2012 Ben Gordon. All rights reserved. #import "ViewController.h" @interface ViewController () @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.
// 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;
if (hourFloat 200 minFloat 200 secFloat 200) { timeLabel.textColor = [UIColor darkGrayColor]; appearanceType.textColor = [UIColor darkGrayColor]; else { timeLabel.textColor = [UIColor whiteColor]; appearanceType.textColor = [UIColor whiteColor];
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 its more accurate [self performSelector:@selector(changeColor) withObject:nil afterDelay:0.05];
UGUI系列-InputField限制输入个数以及限制输入格式 UGUI InputField 组件是一个用来管理输入的组件 我们通常用来输入用户的账号,密码,或者聊天时输入文字,等等输入逻辑… 在使用中,我们常常要对输入的字符串进行限制,最常见的限制有个数和格式
WPF中将16进制颜色码转换成SolidColorBrush 原文:WPF中将16进制颜色码转换成SolidColorBrush 使用ColorConverter.ConvertFromString(string colorValue)方法 例如:new SolidColorBrush((Color)ColorConverter.