纯代码创建UI界面入门(一)
2015-10-13 20:30
537 查看
一、删除main.storyboard,并在info.plist中删除main storyboard file base name
二、在-(BOOL)application:didFinishLauchingWithOptions:中添加以下代码
注:1、由于学习iOS的时候已经是iOS7,所以外国的教程中都推荐用IB来写界面。不过为了更好地理解界面的底层实现,还是要学习以下纯代码编写。
2、因为之前有cocos2d-x的学习经验,所以设置对象,添加子视图的操作还是比较熟悉的。
参考资料:《疯狂ios讲义》
二、在-(BOOL)application:didFinishLauchingWithOptions:中添加以下代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //创建UIWindow对象 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //设置UIWindow的背景色 self.window.backgroundColor = [UIColor whiteColor]; //将该UIWindow对象设为主窗口并显示出来 [self.window makeKeyAndVisible]; //创建一个UIViewController对象 UIViewController *controller = [[UIViewController alloc] init]; self.window.rootViewController = controller; //创建一个UIView对象 UIView *rootView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //设置controller显示rootView controller.view = rootView; //创建一个按钮 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(120, 100, 80, 40); [button setTitle:@"确定" forState:UIControlStateNormal]; [button setTitle:@"取消" forState:UIControlStateHighlighted]; [rootView addSubview:button]; //创建一个UILabel对象 self.show = [[UILabel alloc] initWithFrame:CGRectMake(60, 40, 180, 30)]; [self.show setText:@"初始文本"]; [self.show setBackgroundColor:[UIColor redColor]]; [rootView addSubview:self.show]; //为圆角按钮的触碰事件绑定事件处理方法 [button addTarget:self action:@selector(clickHandler:) forControlEvents:UIControlEventTouchUpInside]; [self.window addSubview:rootView]; // Override point for customization after application launch. return YES; }
- (IBAction)clickHandler:(id)sender { self.show.text = @"hahah"; }
注:1、由于学习iOS的时候已经是iOS7,所以外国的教程中都推荐用IB来写界面。不过为了更好地理解界面的底层实现,还是要学习以下纯代码编写。
2、因为之前有cocos2d-x的学习经验,所以设置对象,添加子视图的操作还是比较熟悉的。
参考资料:《疯狂ios讲义》
相关文章推荐
- android 代码实现控件之间的间距
- GUI - Web前端开发框架
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- [Android]在代码里运行另一个程序的方法
- 评价ui设计作品好坏的八个标准(界面/交互设计研究)
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- 肯特·贝克:改变人生的代码整理魔法
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 网页恶意代码的预防
- 高手写的Tracer-Flash代码调试类代码下载
- CSS代码缩写技巧
- 非主流Q-zOne代码代码搜集第1/2页
- CreateWeb.vbs 代码
- Lua中编译执行代码相关的函数详解
- 更有效率的css代码编写第1/3页
- 为Yahoo! UI Extensions Grid增加内置的可编辑器