在运行时加载XIB文件

先创建一个RuntimeViewController,并且绑定xib,直接上代码:

//导入创建的xib文件

#import "RuntimeViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    //创建一个按钮

    UIButton *myBtn=[[UIButton alloc]initWithFrame:CGRectMake(100, 200, 100, 44)];

    //在按钮上面设置文字

    [myBtn setTitle:@"加载" forState:UIControlStateNormal];

    //为按钮绑定一个点击事件

    [myBtn addTarget:self action:@selector(loadXib) forControlEvents:UIControlEventTouchUpInside];

    //把按钮添加到视图上面

    [self.view addSubview:myBtn];

    // Do any additional setup after loading the view, typically from a nib.

}


-(void)loadXib{

    //创建对象

    RuntimeViewController *rtVC=[[RuntimeViewController alloc]initWithNibName:@"RuntimeViewController" bundle:nil];

    //页面跳转

    [self presentViewController:rtVC animated:YES completion:nil];

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值