iso_study_eighth UiView

来源:互联网 发布:linux 挂载硬盘方式 编辑:程序博客网 时间:2024/04/30 05:16
////  iworkerAppDelegate.m//  UiViewDemo////  Created by shop on 14-5-24.//  Copyright (c) 2014年 sz. All rights reserved.//#import "iworkerAppDelegate.h"@implementation iworkerAppDelegate{    UIView *backView;//全局UIView }- (void)dealloc{    [backView release];//全局释放    [_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.        /*  titlehigh:20px;     *  3GS-320*480;     *  iphone4,4s -640*960;     *  iphone5 640*1136;     */        UIView *mUiView=[[UIView alloc]init];    mUiView.frame=CGRectMake(10, 10, 300, 50);    mUiView.backgroundColor=[UIColor redColor];    [self.window addSubview:mUiView];    [mUiView release];        UIView *mUiView1=[[UIView alloc]init];    mUiView1.frame=CGRectMake(10, 60, 300, 50);    mUiView1.backgroundColor=[UIColor blueColor];    [mUiView addSubview:mUiView1];    [mUiView1 release];        NSLog(@"frame --x=%f",mUiView1.frame.origin.x);    NSLog(@"frame --y=%f",mUiView1.frame.origin.y);    NSLog(@"frame --w=%f",mUiView1.frame.size.width);    NSLog(@"frame --h=%f",mUiView1.frame.size.height);        //得到view的中心点,获取的是view的center;    CGPoint point =mUiView1.center;    NSLog(@"center -x =%f",point.x);    NSLog(@"center -y = %f",point.y);        //得到边框的大小    mUiView1.tag=2;    mUiView1.contentMode=UIViewContentModeBottom;                UIView  *mUiView3=[[UIView alloc]init];    mUiView3.frame=CGRectMake(5, 130, 310, 30);    mUiView3.backgroundColor=[UIColor blackColor];    [self.window addSubview:mUiView3];    [mUiView3 release];        UIView *mUiview4=[[UIView alloc]init];    mUiview4.frame=CGRectMake(5, 5, 100, 20);    mUiview4.backgroundColor=[UIColor whiteColor];    [mUiView3 addSubview:mUiview4];    [mUiview4 release];        UIView *mUIView5=[[UIView alloc]init];    mUIView5.frame=CGRectMake(105, 5, 100, 20);    mUIView5.backgroundColor=[UIColor redColor];    [mUiView3 addSubview:mUIView5];    [mUIView5 release];        UIView *mUiview6=[[UIView alloc]init];    mUiview6.frame=CGRectMake(205, 5, 100, 20);    mUiview6.backgroundColor=[UIColor yellowColor];    [mUiView3 addSubview:mUiview6];    [mUiview6 release];        //得到父类视图,把父类的背景色变成蓝色    UIView *mSuperView=mUiview6.superview;    mSuperView.backgroundColor=[UIColor blueColor];        //获得父视图的数量    NSArray *subViews=mUiView3.subviews;    NSLog(@"count= %d",subViews.count);        for(UIView *view in subViews)    {        view.backgroundColor=[UIColor redColor];//把子视图的颜色全部设置为红色    }        UIView *view0=[subViews objectAtIndex:0];    view0.backgroundColor=[UIColor yellowColor];        UIView *view1=[subViews objectAtIndex:1];    view1.backgroundColor=[UIColor blackColor];            UIView *mUiView7=[[UIView alloc]init];    mUiView7.frame=CGRectMake(5, 170, 310, 50);    mUiView7.backgroundColor=[UIColor blackColor];    //自动剪裁子view,把超出部分剪裁掉    mUiView7.clipsToBounds=YES;    [self.window addSubview:mUiView7];    [mUiView7 release];        UIView *mUiView8=[[UIView alloc]init];    mUiView8.frame=CGRectMake(5, 5, 200, 80);    //设置透明度 数值越大越不透明    mUiView8.alpha=0.5;    mUiView8.backgroundColor=[UIColor greenColor];    [mUiView7 addSubview:mUiView8];    backView=[[UIView alloc]init];    backView.frame=CGRectMake(5, 230, 310, 50);    backView.backgroundColor=[UIColor blackColor];    backView.clipsToBounds=YES;    //autoresizesSubviews 容许子类view 自动布局;    backView.autoresizesSubviews=YES;    [self.window addSubview:backView];    //[mUiView9 release];        UIView *mUiView10=[[UIView alloc]init];    mUiView10.frame=CGRectMake(5, 5, 200, 80);    //设置透明度 数值越大越不透明    mUiView10.alpha=0.5;    //设置自动布局的方式    mUiView10.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;//宽高跟随父控件同时改变    mUiView10.backgroundColor=[UIColor greenColor];    [backView addSubview:mUiView10];    [mUiView10 release];    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timeTick) userInfo:nil repeats:YES];            self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];    return YES;}-(void) timeTick{    backView.frame=CGRectMake(backView.frame.origin.x, backView.frame.origin.y, backView.frame.size.width+5, backView.frame.size.height+5);}- (void)applicationWillResignActive:(UIApplication *)application{    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application{    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application{    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application{    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application{    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end

0 0
原创粉丝点击