设定三原色的值, 生成对应的屏幕背景
来源:互联网 发布:淘宝网2017女装羽绒服 编辑:程序博客网 时间:2024/05/15 23:42
作业效果图
AppDelegate.h文件
#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate,UITextFieldDelegate> //添加协议//编辑环境为MRC, 改用 retain 修饰实例变量@property (retain, nonatomic) UIWindow *window;@end
AppDelegate.m文件
#import "AppDelegate.h"@interface AppDelegate (){//用Extension方法扩展实例变量的作用域 UILabel *redLabel; UILabel *greenLabel; UILabel *blueLabel; UITextField *redTextField; UITextField *greenTextField; UITextField *blueTextField;}@end
@implementation AppDelegate//编辑环境选用的是MRC模式, 需重写dealloc方法- (void)dealloc{ [_window release]; [super dealloc];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; //创建redLabel redLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 80, 30)]; redLabel.backgroundColor = [UIColor redColor]; NSLog(@"%@",[UIFont familyNames]); redLabel.font = [UIFont fontWithName:@"Courier New" size:25]; redLabel.textAlignment = NSTextAlignmentCenter; redLabel.text = @"Red"; redLabel.textColor = [UIColor whiteColor]; [self.window addSubview:redLabel]; [redLabel release]; //创建redTextField redTextField = [[UITextField alloc] initWithFrame:CGRectMake(160, 100, 165, 30)]; redTextField.tag = 101; redTextField.backgroundColor = [UIColor whiteColor]; redTextField.placeholder = @"请输入0-255的数"; redTextField.borderStyle = UITextBorderStyleRoundedRect; [self.window addSubview:redTextField]; [redTextField release]; //创建greenLabel greenLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 150, 80, 30)]; greenLabel.backgroundColor = [UIColor greenColor]; greenLabel.text= @"Green"; greenLabel.textColor = [UIColor whiteColor]; greenLabel.font = [UIFont fontWithName:@"Courier New" size:25]; greenLabel.textAlignment = NSTextAlignmentCenter; [self.window addSubview:greenLabel]; [greenLabel release]; //创建greenTextField greenTextField = [[UITextField alloc] initWithFrame:CGRectMake(160, 150, 165, 30)]; greenTextField.tag = 102; greenTextField.backgroundColor = [UIColor whiteColor]; greenTextField.placeholder = @"请输入0-255的数"; greenTextField.borderStyle = UITextBorderStyleRoundedRect; [self.window addSubview:greenTextField]; [greenTextField release]; //创建blueLabel blueLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 80, 30)]; blueLabel.backgroundColor = [UIColor blueColor]; blueLabel.text = @"Blue"; blueLabel.textColor = [UIColor whiteColor]; blueLabel.textAlignment = NSTextAlignmentCenter; blueLabel.font = [UIFont fontWithName:@"Courier New" size:25]; [self.window addSubview:blueLabel]; [blueLabel release]; //创建blueTextField blueTextField = [[UITextField alloc] initWithFrame:CGRectMake(160, 200, 165, 30)]; blueTextField.tag = 103; blueTextField.backgroundColor = [UIColor whiteColor]; blueTextField.placeholder = @"请输入0-255的数"; blueTextField.borderStyle = UITextBorderStyleRoundedRect; [self.window addSubview:blueTextField]; [blueTextField release]; //创建okButton UIButton *okButton = [UIButton buttonWithType:UIButtonTypeSystem]; okButton.frame = CGRectMake(150, 280, 75, 30); okButton.backgroundColor = [UIColor whiteColor]; [okButton setTitle:@"确定" forState:UIControlStateNormal]; [self.window addSubview:okButton]; [okButton addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
点击按钮的submit的方法实现
- (void)submit { CGFloat Red, Green, Blue; Red = [redTextField.text integerValue] / 255.; Green = [greenTextField.text integerValue] / 255.; Blue = [blueTextField.text integerValue] / 255.; self.window.backgroundColor = [UIColor colorWithRed: Red green:Green blue:Blue alpha:1.0];}
下一篇用 tag值方法 实现相反操作
0 0
- 设定三原色的值, 生成对应的屏幕背景
- 光学三原色与色的三原色
- 人生的三原色
- OC简单小功能的实现-利用三个代表三原色的滑块控制背景颜色变化
- 三基色、三原色的区别
- MyEclipse中背景颜色的设定
- 研究员的三原色——记华先胜博士
- jQuery插件实现红绿蓝三原色的搭配
- 色彩三原色和合并颜色的学习
- 网页打印中,A4纸对应的像素值的设定和换算
- 返回设定日期对应月份的上月月初(末)日期
- 设置Activity对应屏幕标题的图标
- 屏幕密度和DPI的对应关系
- Bootstrap : 栅格对应的屏幕尺寸
- protobuf 生成对应的文件
- myeclipse设定代码自动生成的风格
- android item的背景颜色 显示效果设定
- 设定xfce工具栏图标背景的几种方法
- http协议断点续传
- 九度OJ 1029:魔咒词典 (排序)
- 装饰者模式
- angular controller 依赖声明
- QTableView基本用法讲解,Qt表格控件的使用方法
- 设定三原色的值, 生成对应的屏幕背景
- Python迭代器和生成器
- Android学习第四天之AbsoluteLayout绝对布局
- android去掉 radio 或 checkBox 的默认图标,用自己的图标
- 链式栈
- 汉语字典
- quartz_jobs.xml配置文件样例2--CronTrigger
- 九度OJ 1030:毕业bg (01背包、DP)
- C#中的 int? int??是什么意思