zoukankan      html  css  js  c++  java
  • 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
    
  • 相关阅读:
    (一)RabbitMQ安装与基本配置
    一文搞懂网络层
    分布式锁的实现之 redis 篇
    浅谈synchronized和volatitle实现线程安全的策略
    JUC包的线程池详解
    Curling 2.0 POJ
    第三章处理机调度与死锁
    Java异常学习笔记
    Java对象学习笔记-下
    Java对象学习笔记-上
  • 原文地址:https://www.cnblogs.com/0515offer/p/4638423.html
Copyright © 2011-2022 走看看