zoukankan      html  css  js  c++  java
  • iOS UI01_UIView

    //

    //  AppDelegate.m

    //  UI01_UIView

    //

    //  Created by dllo on 15/7/29.

    //  Copyright (c) 2015 zhozhicheng. All rights reserved.

    //


    #import "AppDelegate.h"


    @interface AppDelegate ()


    @property(nonatomic,retain)UIView *myView;


    //

    #define WIDTH self.window.frame.size.width

    #define HEIGHT self.window.frame.size.height



    @end


    @implementation AppDelegate

    -(void)dealloc

    {

        [_myView release];

        [_window release];

        [superdealloc];

    }


    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        //创建一个和屏幕一般大的window

        self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

        // Override point for customization after application launch.

        //window一个背景颜色

        self.window.backgroundColor = [UIColoryellowColor];

        //让当前的window在应用程序中可见并显示出来

        [self.windowmakeKeyAndVisible];

        //window进行释放

        [_window release];

        

        //UIView

        // 1.创建一个UIView的对象

       UIView *view1=[[UIViewalloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

        // 2.view1设置背景颜色

        view1.backgroundColor=[UIColorblueColor];

        // 3.把视图贴到窗体上

        [self.windowaddSubview:view1];

        // 4.释放

        [view1release];

        //视图加入到父视图的数组之后,数组会添加视图的引用计数,对应的也就能够在加入之后对视图进行释放

        

        

       UIView *view2=[[UIViewalloc] initWithFrame:CGRectMake(130, 130, 100, 100)];

        view2.backgroundColor=[UIColorwhiteColor];

        [self.windowaddSubview:view2];

        [view2release];

        

       UIView *view3=[[UIViewalloc] initWithFrame:CGRectMake(160, 160, 100, 100)];

        view3.backgroundColor=[UIColorredColor];

        [self.windowaddSubview:view3];

        [view3release];

        //视图的坐标起始位置在自己的父视图的左上角

       NSLog(@"%g",WIDTH);

       NSLog(@"%g",HEIGHT);

        //一个视图能够有多个子视图,可是一个视图仅仅能有一个父视图

        // 父视图

       NSLog(@"%@",view2.superview);

        

        // 子视图

        NSLog(@"%@",self.window.subviews);

        //先创建,先加入到subview的视图会在层级关系的最以下

        //通过父视图来管理他身上全部子视图的层级关系

        //父视图把指定的子视图放在最上面

        [self.windowbringSubviewToFront:view2];

        //父视图把指定的子视图放在最以下

        [self.windowsendSubviewToBack:view2];

        

        //用视图的frame属性,对视图位置大小进行又一次设置

        view1.frame=CGRectMake(190, 190, 120, 120);

        

        self.myView =[[UIViewalloc] initWithFrame:CGRectMake(200, 200, 100, 100)];

        self.myView.backgroundColor=[UIColorgrayColor];

        [self.windowaddSubview:self.myView];

        [_myView release];


        // 透明度

        view3.alpha = 0.5;

        // tag

        // tag设置不能为0,不能反复

        view1.tag = 1000;

       UIView *tempView = [self.windowviewWithTag:1000];

       NSLog(@"%p",tempView);

       NSLog(@"%p",view1);


        return YES;

    }

    - (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


  • 相关阅读:
    Swagger 专题
    Spring boot中使用springfox来生成Swagger Specification小结
    Android导航菜单横向左右滑动并和下方的控件实现联动
    Android 日历控件 mCalendarView
    22个值得收藏的android开源代码-UI篇
    java获得指定日期的前一天,后一天的代码
    Java获取当前日期的前一个月,前一天的时间
    Android 获取当前日期算前一年、前一月、前一天Calendar
    [Android]通过setImageURI设置网络上面的图片
    Android-PullToRefresh 使用心得
  • 原文地址:https://www.cnblogs.com/llguanli/p/7006974.html
Copyright © 2011-2022 走看看