---
title: "iOS Dev (12) UIView、UIImage和UILabel"
author: "prevention"
date: "2014-01-02T01:18:00Z"
tags: []
slug: "ios-dev-12-uiview-uiimage-uilabel"
draft: false
lastmod: "2014-02-03T16:56:22Z"
id: 2010883
url: "https://prevention.iteye.com/blog/2010883"
---

# iOS Dev (12) UIView、UIImage和UILabel

- 作者：CSDN 大锐哥
- 地址：[http://blog.csdn.net/prevention](http://blog.csdn.net/prevention)

## AppDelegate

.h

```
#import <UIKit/UIKit.h>

@class ViewController;
@interface AppDelegate: UIResponder<UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController;

@end
```

.m

```
#import "AppDelegate.h"
#import "ViewController.h"

@implementation AppDelegate

- (BOOL) application: (UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    ViewController *viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
    self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];

    return YES;
}

- (void) applicationWillResignActive: (UIApplication *)application
{
}

- (void) applicationDidEnterBackground: (UIApplication *)application
{
}

- (void) applicationWillEntreForeground: (UIApplication *)application
{
}

- (void) applicationDidBecomeActive: (UIApplication *)application
{
}

- (void) applicationWillTerminate: (UIApplication *)application
{
}

@end
```

## ViewController

.h

```
#import <UIKit/UIKit.h>

@interface ViewController: UIViewController

@end
```

.m

```
#import "ViewController.h"

@interface ViewController ()
@end

@implementation ViewController

- (void) viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor redColor];

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 200, 100)];
    view.backgroundColor = [UIColor colorWithRed:1.0 green:0 blue:0 alpha:0.6];
    [self.view addSubView:view];

    UIImage *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 210, 200, 100)];
    imageView.backgroundColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0.6];
    [self.view addSubView:imageView];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 220, 200, 100)];
    label.backgroundColor = [UIColor colorWithRed:0 green:1.0 blue:1.0 alpha:0.6];
    [self.view addSubView:label];
}

- (void) didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
```