设定三原色的值, 生成对应的屏幕背景
2015-10-17 16:08
148 查看
作业效果图
![](http://img.blog.csdn.net/20151017153722260)
AppDelegate.h文件
AppDelegate.m文件
点击按钮的submit的方法实现
下一篇用 tag值方法 实现相反操作
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值方法 实现相反操作
相关文章推荐
- http协议断点续传
- mybatis 为什么要设置jdbcType
- 【极度涉及】CSS各种居中方法
- OpenCV】访问图像中每个像素的值
- 等待唤醒机制
- 装饰者模式
- 九度OJ 1029:魔咒词典 (排序)
- GitHub详细教程
- 极限理论
- 九度OJ 1029:魔咒词典 (排序)
- lintcode :最长上升连续子序列
- Win10电脑版Cortana微软小娜发送短信演示视频
- 30SkypeForBusiness2015进阶篇--启用AllwaysOn并创建可用性组
- HttpURLConnection用法详解
- jsp之c标签用法实例分析
- View控件的学习
- uboot初始化中,为何要设置CPU为SVC模式而不是设置为其他模式
- android自定义键盘
- 进程是个啥
- javascript 案例(二)表格的操作(上)