#import "AppDelegate.h"
@interface AppDelegate ()
@property(nonatomic,assign)NSArray *apps;
@end
@implementation AppDelegate
-(void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#if 0
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor cyanColor];
[self.window makeKeyAndVisible];
self.window.rootViewController = [[UIViewController alloc]init];
UIView *oneView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
[oneView setBackgroundColor:[UIColor yellowColor]];
[self.window addSubview:oneView];
[oneView release];
oneView.frame = CGRectMake(100, 100, 100, 100);
NSLog(@"subView: %@ ",self.window.subviews);
NSLog(@" superView: %@ ",oneView.superview);
NSLog(@"%@",NSStringFromCGRect(self.window.frame));
oneView.center = CGPointMake(100, 100);
oneView.hidden = YES;
oneView.alpha = 1.0;
oneView.tag = 1000;
UIView *tagView = [self.window viewWithTag:1000];
tagView.backgroundColor = [UIColor whiteColor];
[_window release];
#endif
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor colorWithRed:248/255.0 green:195/255.0 blue:205/255.0 alpha:1];
[self.window makeKeyAndVisible];
self.window.rootViewController = [[UIViewController alloc]init];
#if 0
UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
aView.backgroundColor = [UIColor cyanColor];
[self.window addSubview:aView];
[aView release];
UIView *bView = [[UIView alloc]initWithFrame:aView.frame];
bView.backgroundColor = [UIColor yellowColor];
[self.window addSubview:bView];
[bView release];
UIView *temp = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
temp.backgroundColor = [UIColor whiteColor];
[self.window addSubview:temp];
temp.tag = 1000;
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(repeat) userInfo:nil repeats:YES];
#endif
#warning homework-one
#if 0
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(70, 70, 100, 100)];
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(90, 90, 100, 100)];
UIView *view4 = [[UIView alloc]initWithFrame:CGRectMake(110, 110, 100, 100)];
UIView *view5 = [[UIView alloc]initWithFrame:CGRectMake(130, 130, 100, 100)];
view1.backgroundColor = [UIColor redColor];
view2.backgroundColor = [UIColor yellowColor];
view3.backgroundColor = [UIColor greenColor];
view4.backgroundColor = [UIColor blueColor];
view5.backgroundColor = [UIColor lightGrayColor];
[self.window addSubview:view1];
[self.window addSubview:view2];
[self.window addSubview:view3];
[self.window addSubview:view4];
[self.window addSubview:view5];
view5.alpha = 0.5;
view4.hidden = YES;
view4.center = CGPointMake(150, 150);
[view1 release];
[view2 release];
[view3 release];
[view4 release];
[view5 release];
#endif
#warning homework-second
#if 0
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(40, 60, 80, 40)];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(40, 130, 80, 40)];
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(160, 60, 120, 40)];
UIView *view4 = [[UIView alloc]initWithFrame:CGRectMake(160, 130, 120, 40)];
UIView *view5 = [[UIView alloc]initWithFrame:CGRectMake(80, 200, 60, 40)];
UIView *view6 = [[UIView alloc]initWithFrame:CGRectMake(170, 200, 60, 40)];
view1.backgroundColor = [UIColor cyanColor];
view2.backgroundColor = [UIColor cyanColor];
view3.backgroundColor = [UIColor cyanColor];
view4.backgroundColor = [UIColor cyanColor];
view5.backgroundColor = [UIColor cyanColor];
view6.backgroundColor = [UIColor cyanColor];
[self.window addSubview:view1];
[self.window addSubview:view2];
[self.window addSubview:view3];
[self.window addSubview:view4];
[self.window addSubview:view5];
[self.window addSubview:view6];
[view6 release];
[view5 release];
[view4 release];
[view3 release];
[view2 release];
[view1 release];
#endif
#warning homework thrid
#if 1
int totalloc=3;
CGFloat appvieww=80;
CGFloat appviewh=90;
CGFloat margin=(self.window.frame.size.width-totalloc*appvieww)/(totalloc+1);
int count=self.apps.count;
for (int i=0; iint row=i/totalloc;
int loc=i%totalloc;
CGFloat appviewx=margin+(margin+appvieww)*loc;
CGFloat appviewy=margin+(margin+appviewh)*row;
UIView *appview=[[UIView alloc]initWithFrame:CGRectMake(appviewx, appviewy, appvieww, appviewh)];
[appview setBackgroundColor:[UIColor purpleColor]];
[self.window addSubview:appview];
appview.tag = 1000;
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(repeat) userInfo:nil repeats:YES];
[self.window addSubview:appview];
#endif
[_window release];
}
return YES;
}
-(void)repeat
{
UIView *appview = [self.window viewWithTag:1000];
appview.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1];
[self.window addSubview:appview];
}
@end