UI3_ViewController初步

//
//  AppDelegate.m
//  UI3_ViewController初步
//
//  Created by zhangxueming on 15/6/30.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //视图控制器
    //包含视图部分及控制部分
    //通过视图控制器管理视图
    NSLog(@"rootViewController = %@", self.window.rootViewController);
    self.window.backgroundColor = [UIColor cyanColor];
    return YES;
}

 

//
//  ViewController.m
//  UI3_ViewController初步
//
//  Created by zhangxueming on 15/6/30.
//  Copyright (c) 2015年 zhangxueming. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    CGRect rect = CGRectMake(20,100, self.view.frame.size.width-40, self.view.frame.size.height-200);
    self.view.frame = rect;
    NSLog(@"view = %@", self.view);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    CGRect rect = CGRectMake(20,100, self.view.frame.size.width-40, self.view.frame.size.height-200);
    self.view.frame = rect;
    
    self.view.backgroundColor = [UIColor redColor];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    [btn setTitle:@"点击我" forState:UIControlStateNormal];
    [btn setTitle:@"背景颜色被修改" forState:UIControlStateHighlighted];
    btn.frame = CGRectMake(20,100, self.view.frame.size.width-40, 50);
    btn.backgroundColor = [UIColor yellowColor];
    [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    btn.tag = 100;
    [self.view addSubview:btn];
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeSystem];
    [btn1 setTitle:@"点击我" forState:UIControlStateNormal];
    [btn1 setTitle:@"背景颜色被修改" forState:UIControlStateHighlighted];
    btn1.frame = CGRectMake(20,200, self.view.frame.size.width-40, 50);
    btn1.backgroundColor = [UIColor yellowColor];
    [btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    btn1.tag = 101;
    [self.view addSubview:btn1];
}

- (void)btnClicked:(UIButton *)btn
{
    if (btn.tag==100) {
        self.view.backgroundColor = [UIColor purpleColor];
    }
    else if (btn.tag==101)
    {
        self.view.backgroundColor = [UIColor blueColor];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

posted @ 2015-07-11 12:49  sirzhang  阅读(157)  评论(0编辑  收藏  举报
AmazingCounters.com