新手UIView学习
查看次数:1561
下载次数:126
上传时间:2015-10-17
大小:29 B
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor yellowColor];
[self.window makeKeyAndVisible];
UILabel *red = [[UILabel alloc] initWithFrame:CGRectMake(30, 100, 90, 30)];
red.backgroundColor = [UIColor redColor];
red.text = @"Red";
red.textColor = [UIColor whiteColor];
red.textAlignment = NSTextAlignmentCenter;
red.font = [UIFont systemFontOfSize:25];
[self.window addSubview:red];
[red release];
UITextField *redNumber = [[[UITextField alloc] initWithFrame:CGRectMake(140, 95, 200, 40)] autorelease];
redNumber.borderStyle = UITextBorderStyleRoundedRect;
redNumber.placeholder = @"输入0~255之间的数字";
redNumber.keyboardType = UIKeyboardTypeNumberPad;
redNumber.tag = 101;
[self.window addSubview:redNumber];
UILabel *green = [[UILabel alloc] initWithFrame:CGRectMake(30, 160, 90, 30)];
green.backgroundColor = [UIColor greenColor];
green.text = @"Green";
green.textColor = [UIColor whiteColor];
green.textAlignment = NSTextAlignmentCenter;
green.font = [UIFont systemFontOfSize:25];
[self.window addSubview:green];
[green release];
UITextField *greenNumber = [[[UITextField alloc] initWithFrame:CGRectMake(140, 155, 200, 40)] autorelease];
greenNumber.borderStyle = UITextBorderStyleRoundedRect;
greenNumber.placeholder = @"输入0~255之间的数字";
greenNumber.keyboardType = UIKeyboardTypeNumberPad;
greenNumber.tag = 102;
[self.window addSubview:greenNumber];
UILabel *blue = [[UILabel alloc] initWithFrame:CGRectMake(30, 220, 90, 30)];
blue.text = @"Blue";
blue.backgroundColor = [UIColor blueColor];
blue.textAlignment = NSTextAlignmentCenter;
blue.textColor = [UIColor whiteColor];
blue.font = [UIFont systemFontOfSize:25];
[self.window addSubview:blue];
[blue release];
UITextField *blueNumber = [[[UITextField alloc] initWithFrame:CGRectMake(140, 215, 200, 40)] autorelease];
blueNumber.borderStyle = UITextBorderStyleRoundedRect;
blueNumber.placeholder = @"输入0~255之间的数字";
blueNumber.keyboardType = UIKeyboardTypeNumberPad;
blueNumber.tag = 103;
[self.window addSubview:blueNumber];
UIButton *submit = [UIButton buttonWithType:UIButtonTypeSystem];
submit.backgroundColor = [UIColor colorWithRed:0.257 green:1.000 blue:0.972 alpha:1.000];
submit.frame = CGRectMake(160, 300, 60, 40);
[submit setTitle:@"提交" forState:UIControlStateNormal];
[self.window addSubview:submit];
[submit addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
return YES;
}
- (void)submit {
UITextField *temp101 = (UITextField *)[self.window viewWithTag:101];
UITextField *temp102 = (UITextField *)[self.window viewWithTag:102];
UITextField *temp103 = (UITextField *)[self.window viewWithTag:103];
self.window.backgroundColor = [UIColor colorWithRed:[temp101.text intValue] / 255.0 green:[temp102.text intValue]/ 255.0 blue:[temp103.text intValue] / 255.0 alpha:1];
}
收藏