标签:ios 界面 interface uiview cocoa touch
一、XIB的适用范围
xib(也叫Nib)与storyboard一样是用来描述界面的。
// // XNViewController.m // 09xib的使用, 只是简单的加载xib, 没有设置filesowner不能进行连线. // // Created by neng on 14-6-5. // Copyright (c) 2014年 neng. All rights reserved. // #import "XNViewController.h" @interface XNViewController () { BOOL _sign;//测试玩 } @end @implementation XNViewController - (void)viewDidLoad { [super viewDidLoad]; _sign = NO; [self myLoadXib]; } /**加载xib*/ -(void)myLoadXib { //1.加载xib NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"MyXIB" owner:nil options:nil]; //2.取出xib中的view并添加到父视图 UIView *myView = views[0]; UIButton *btn1 = (UIButton *)[myView viewWithTag:1]; UIButton *btn2 = (UIButton *)[myView viewWithTag:4]; [btn1 addTarget:self action:@selector(myClick) forControlEvents:UIControlEventTouchUpInside]; [btn2 addTarget:self action:@selector(myClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:myView]; //NSLog(@"%d",views.count); //返回的数组是视图的个数(不包括子视图) //另取一个.(数组中的顺序是根据xib文件中的的顺序来的) UIButton *btn = views[1]; btn.frame = CGRectMake(0, 333, btn.frame.size.width, btn.frame.size.height); [btn addTarget:self action:@selector(myClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; } /**xib中的监听按钮点击事件, 点击后使storyboard中label文字改变*/ -(void)myClick { _sign = !_sign; if (_sign) { _myLabel.text = @"Hello!"; }else{ _myLabel.text = @"World!"; } } @end
【iOS】Xib的使用与File'Owner总结,布布扣,bubuko.com
标签:ios 界面 interface uiview cocoa touch
原文地址:http://blog.csdn.net/xn4545945/article/details/31786391