随机色
#import "AppDelegate.h"
#import "code-ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (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 whiteColor];
code_ViewController *code = [[code_ViewController alloc]init];
self.window.rootViewController = code;
[code release];
[self.window makeKeyAndVisible];
return YES;
}
#import "code-ViewController.h"
#import "TouchView.h"
@interface code_ViewController ()
@end
@implementation code_ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
TouchView *view = [[TouchView alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
view.backgroundColor = [UIColor blueColor];
[self.view addSubview:view];
[view release];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#import "TouchView.h"
@implementation TouchView
// 取随机颜色
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
int random1 = arc4random() % 256;
int random2 = arc4random() % 256;
int random3 = arc4random() % 256;
self.backgroundColor = [UIColor colorWithRed:random1/255.0 green:random2/255.0 blue:random3/255.0 alpha:1.0];
}