#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
#import "AppDelegate.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];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIView *redView = [[UIView alloc] initWithFrame:(CGRectMake(50, 10, 100, 20))];
UIView *blueView = [[UIView alloc] initWithFrame:(CGRectMake(50, 30, 100, 20)) ];
UIView *blackView = [[UIView alloc] initWithFrame:(CGRectMake(50,50 , 100, 20))];
UIView *purpleView = [[UIView alloc] initWithFrame:(CGRectMake(50, 70, 100, 20))];
UIView *yellowView = [[UIView alloc] initWithFrame:(CGRectMake(50, 90, 100, 20))];
UIView *grayView = [[UIView alloc] initWithFrame:(CGRectMake(50, 110, 100, 20))];
UIView *greenView = [[UIView alloc]initWithFrame:(CGRectMake(50, 130, 100, 20))];
UIView *orangeView = [[UIView alloc] initWithFrame:(CGRectMake(50, 150, 100, 20))];
orangeView.backgroundColor = [UIColor orangeColor];
[self.window addSubview:orangeView];
[orangeView release];
CGRect rec = orangeView.frame;
rec.origin.y = 200;
orangeView.frame = rec;
CGRect rec1 = blackView.frame;
rec1.origin.x = 200;
blackView.frame = rec1;
redView.backgroundColor = [UIColor redColor];
blueView.backgroundColor = [UIColor blueColor];
blackView.backgroundColor = [UIColor blackColor];
purpleView.backgroundColor = [UIColor purpleColor];
yellowView.backgroundColor = [UIColor yellowColor];
grayView.backgroundColor = [UIColor grayColor];
greenView.backgroundColor = [UIColor greenColor];
[self.window addSubview:redView];
[self.window addSubview:blackView];
[self.window addSubview:blueView];
[self.window addSubview:purpleView];
[self.window addSubview:yellowView];
[self.window addSubview:grayView];
[self.window addSubview:greenView];
[redView release];
[blueView release];
[blackView release];
[purpleView release];
[yellowView release];
[grayView release];
[greenView release];
UIView *view1 = [[UIView alloc] initWithFrame:(CGRectMake(100, 100, 200, 200))];
view1.backgroundColor = [UIColor magentaColor];
[self.window addSubview:view1];
UIView *subView = [[UIView alloc] initWithFrame:(CGRectMake(100, 100, 100, 100))];
subView.backgroundColor = [UIColor blueColor];
[view1 addSubview:subView];
CGRect rect = view1.bounds;
rect.origin.x = 100;
view1.bounds = rect;
CGRect rec2 = view1.bounds;
rec2.size = CGSizeMake(300, 300);
view1.bounds = rec2;
NSLog(@"%f %f", view1.bounds.origin.x, view1.bounds.origin.y);
[view1 release];
UIView *red1View = [[UIView alloc] initWithFrame:(CGRectMake(100, 100, 100, 100))];
redView.backgroundColor = [UIColor redColor];
[self.window addSubview:red1View];
[red1View release];
UIView *orange1View = [[UIView alloc] initWithFrame:(CGRectMake(150, 150, 100, 100))];
orange1View.backgroundColor = [UIColor orangeColor];
[self.window insertSubview:orange1View atIndex:1];
[orange1View release];
UIView *yellow1View = [[UIView alloc] initWithFrame:(CGRectMake(200, 200, 100, 100))];
yellow1View.backgroundColor = [UIColor yellowColor];
[self.window insertSubview:yellow1View atIndex:2];
[yellow1View release];
UIView *blue1View = [[UIView alloc] initWithFrame:(CGRectMake(250, 250, 100, 100))];
blue1View.backgroundColor = [UIColor blueColor];
[self.window insertSubview:blue1View aboveSubview:yellow1View];
[blue1View release];
UIView *black1View = [[UIView alloc] initWithFrame:(CGRectMake(225, 225, 100, 100))];
black1View.backgroundColor = [UIColor blackColor];
[self.window insertSubview:black1View belowSubview:blue1View];
[black1View release];
UIView *green1View = [[UIView alloc] initWithFrame:(CGRectMake(50, 50, 100, 100))];
green1View.backgroundColor = [UIColor greenColor];
[self.window addSubview:green1View];
[green1View release];
for (UIView *view in self.window.subviews) {
NSLog(@"%lu %p", [self.window.subviews count], self.window.subviews);
[view removeFromSuperview];
}
UIView *aView = [[UIView alloc] initWithFrame:(CGRectMake(100, 100, 100, 100))];
aView.backgroundColor = [UIColor redColor];
[self.window addSubview:aView];
[aView release];
UIView *bView = [[UIView alloc] initWithFrame:(CGRectMake(125, 125, 100, 100))];
bView.backgroundColor = [UIColor blueColor];
[self.window insertSubview:bView atIndex:1];
[bView release];
UIView *cView = [[UIView alloc] initWithFrame:(CGRectMake(150, 150, 100, 100))];
cView.backgroundColor = [UIColor blackColor];
[self.window insertSubview:cView atIndex:2];
[cView release];
UIView *dView = [[UIView alloc] initWithFrame:(CGRectMake(175, 175, 100, 100))];
dView.backgroundColor = [UIColor purpleColor];
[self.window insertSubview:dView atIndex:3];
[dView release];
UIView *eView = [[UIView alloc] initWithFrame:(CGRectMake(200, 200, 100, 100))];
eView.backgroundColor = [UIColor orangeColor];
[self.window insertSubview:eView atIndex:4];
[eView release];
[self.window bringSubviewToFront:aView];
[self.window sendSubviewToBack:cView];
[self.window exchangeSubviewAtIndex:3 withSubviewAtIndex:4];
[cView removeFromSuperview];
UIView *tagView = [[UIView alloc] initWithFrame:(CGRectMake(100, 100, 200, 200))];
tagView.backgroundColor = [UIColor redColor];
tagView.tag = 10;
[self.window addSubview:tagView];
[tagView release];
UIView *view = [self.window viewWithTag:10];
view.backgroundColor = [UIColor yellowColor];
tagView.hidden = NO;
tagView.alpha = 0.5;
UIView *superView = [tagView superview];
superView.backgroundColor = [UIColor yellowColor];
for (UIView *view in self.window.subviews) {
if (view.tag == 10) {
UIView *tagView = [self.window viewWithTag:10];
tagView.backgroundColor = [UIColor yellowColor];
}
}
UIView *black2View = [[UIView alloc] initWithFrame:(CGRectMake(100, 100, 100, 100))];
black2View.backgroundColor = [UIColor blackColor];
[tagView addSubview:blackView];
[black2View release];
UIView *orange2View = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, 100, 100))];
orange2View.backgroundColor = [UIColor orangeColor];
[tagView addSubview:orange2View];
[orange2View release];
black2View.tag = 11;
orange2View.tag = 12;
NSArray *subViews = [tagView subviews];
for (UIView *view in subViews) {
if (view.tag == 11) {
view.backgroundColor = [UIColor blueColor];
}else if (view.tag == 12){
view.backgroundColor = [UIColor cyanColor];
}
}
return YES;
}
@end