2015-12-24-Xib Xib 使用

//
// AppDelegate.h
// UI14_Xib
//
// Created by YIem on 15/12/24.
// Copyright © 2015年 www.yiem.net YIem博客. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder

@property (strong, nonatomic) UIWindow *window;

@end


//
// AppDelegate.m
// UI14_Xib
//
// Created by YIem on 15/12/24.
// Copyright © 2015年 www.yiem.net YIem博客. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    ViewController *movieVC = [[ViewController alloc] init];
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:movieVC];
    navi.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1000];
    UITabBarController *tabBarVC = [[UITabBarController alloc] init];
    tabBarVC.viewControllers = @[navi];
    self.window.rootViewController = tabBarVC;

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



//
// ViewController.h
// UI14_Xib
//
// Created by YIem on 15/12/24.
// Copyright © 2015年 www.yiem.net YIem博客. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end


//
// ViewController.m
// UI14_Xib
//
// Created by YIem on 15/12/24.
// Copyright © 2015年 www.yiem.net YIem博客. All rights reserved.
//

#import "ViewController.h"
#import "MyView.h"
@interface ViewController ()

@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"Xib";

    // Xib 使用
    // 参数1. Xib文件名
    // 参数2. Xib文件拥有者
    // 参数3. nil
    MyView *view = [[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil] lastObject];
    view.aLabel.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
    //
    }

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

@end



//
// MyView.h
// UI14_Xib
//
// Created by YIem on 15/12/24.
// Copyright © 2015年 www.yiem.net YIem博客. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MyView : UIView
// 脱线
@property (weak, nonatomic) IBOutlet UILabel *aLabel;
@property (weak, nonatomic) IBOutlet UITextField *aTextField;
@end


//
// MyView.m
// UI14_Xib
//
// Created by YIem on 15/12/24.
// Copyright © 2015年 www.yiem.net YIem博客. All rights reserved.
//

#import "MyView.h"

@interface MyView ()
@property (weak, nonatomic) IBOutlet UIButton *aButton;

@end

@implementation MyView

  • (IBAction)buttonClick:(UIButton *)sender {
    NSLog(@"滴滴滴" );
    }

/* // Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.

  • (void)drawRect:(CGRect)rect {
    // Drawing code
    }
    */

@end



标签: none

添加新评论

Title - Artist
0:00