UI 自定义view

//
//  VisionAppDelegate.m
//  自定义view
//
//  Copyright (c) 2014年 Vision. All rights reserved.
//

#import "VisionAppDelegate.h"
#import "VisionLTView.h"
@implementation VisionAppDelegate


//应用程序加载完成就会调用这个方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    for (int i = 1; i < 6; i++) {
        VisionLTView *test = [[VisionLTView alloc]initWithFrame:CGRectMake(10, 50 + 50 * i, 280, 40)];
        test.backgroundColor = [UIColor whiteColor];
        if (i < 6) {
        test.label.text = @"文字";
        }

        test.tag = 1000 + i;
        [self.window addSubview:test];
        [test release];
    }
    
    
    NSLog(@"%s",__func__);
    
    
    [_window release];
    return YES;
}
- (void)dealloc
{
    [_window release];
    [super dealloc];
    NSLog(@"%s",__func__);
}
- (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.
    NSLog(@"%s",__func__);
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    
//    进入后台 尽可能的保存用户数据,方便用户重新激活应用时,快速恢复原来的状态
    
    //去释放共有的资源,暂停计时器(NSTimer)
    // 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.
    NSLog(@"%s",__func__);
}

- (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.
    NSLog(@"%s",__func__);
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    //重启所有的之前被暂停的任务
    //刷新UI界面
    // 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.

    NSLog(@"%s",__func__);
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    //当应用程序被退出的时候调用
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    NSLog(@"%s",__func__);
}

@end


//
//  VisionLTView.h

//  Copyright (c) 2014年 Vision. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface VisionLTView : UIView
//把自定义的view上附带的控件设置成属性
@property(nonatomic, retain) UILabel *label;
@property(nonatomic, retain) UITextField *textField;


@end

//
//  VisionLTView.m
//  自定义view_09_26
//
//  Created by Vision on 14-9-26.
//  Copyright (c) 2014年 Vision. All rights reserved.
//

#import "VisionLTView.h"

@implementation VisionLTView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        //在这里对控件进行初始化设置
        
        //frame根据父视图的frame设定
        self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width / 3 - 20, frame.size.height)];
        self.label.backgroundColor = [UIColor redColor];
        [self addSubview:self.label];
        [_label release];
        
        self.textField = [[UITextField alloc] initWithFrame:CGRectMake(frame.size.width / 3 , 0, frame.size.width / 3 * 2 - 2, frame.size.height)];
        self.textField.backgroundColor = [UIColor yellowColor];
        [self addSubview:self.textField];
        [_textField release];
        
        
        
    }
    return self;
}
- (void)dealloc
{
    [_textField release];
    [_label release];
    [super dealloc];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值