ios开发-无界面设计文件开发

来源:互联网 发布:淘宝上开网店要钱吗 编辑:程序博客网 时间:2024/06/07 22:15

删除Main.stroyboard文件和ViewController.h和ViewController.m文件

程序需要修改IOS代理的application:didFinishLaunchingWithOption:方法

实例:重写该方法

self.windoe=[[UIwindow alloc] initWithFrame:[UIScreen mainScreen].bounds];---创建UIWindow对象,将其初始化为与屏幕大小相同

self.window.backgroundColor=[UIColor whiteColor];-----设置白色背景

UIViewController* controller=[[UIViewController alloc] init];----创建一个UIViewController对象

self.window.rootViewController=controller;------程序窗口加载并显示viewController视图控制器关联的用户界面

UIView* rootView=[[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];--------创建一个UIview对象

controller.view=rootView;------设置controller显示rootView控件

UIButton* button=[UIButton buttonWithType:UIButtonTypeSystem];--------创建一系统风格的button

button.frame=CGRectMake(120,100,80,40);-------设置按钮的大小

[button setTitle:@"OK" forState:UIControlStateNormal];-----设置button的数据

[rootView addSubview:button];------将button添加到rootView控件中

self.show=[[UILabel alloc] initWithFrame:CGRectMake(60,40,180,30);-----创建一个UILable对象,并设置大小

[rootView addSubview:self.show];-----将该文本框添加到view中

self.show.text=@"tex";

self.show.backgroundColor=[UIColor grayColor];----------设置UILable的显示

[button addTarget:self  action:@selector(tappedHandler:) forControlEvents:UIControlEventTouchUpInside];--------为按钮添加点击事件

[self.window makeKeyAndVisable];------将该UIWindow显示出来

return YES;

写入点击事件触发的方法:

-(void) tappedHandler:(UIButton*) sender{

//方法体

}

步骤:创建UIWindow作为应用程序的窗口,后创建UIView作为UIWindow显示的根目录,显示需要借助UIViewController。

创建UIView作为容器后,首先创建ui控件;然后调用addSubView方法将UI控件添加到其他容器中;最后调用UI控件的setter方法来设置UI控件。

0 0