ios without interface builder 开发
mlyixi
posted @ 2012年5月09日 19:58
in 未分类
with tags
ios without ib
, 1435 阅读
一.视图
把自定义视图控制器赋给Delegation-window-rootViewController,在自定义视图控制器的loadView方法中初始化view.
@class NOIBViewController; @property (strong, nonatomic) NOIBViewController *viewController;
self.window.rootViewController = viewController;
@property (strong, nonatomic) UILabel *label;
- (void)loadView { CGRect frame = CGRectMake(0, 0, 320, 480); self.view = [[UIView alloc] initWithFrame:frame]; self.view.backgroundColor = [UIColor whiteColor]; frame = CGRectMake(0, 0, 100, 50); label = [[UILabel alloc] initWithFrame:frame]; label.text = @"hello world"; [self.view addSubview:label]; }
二. 事件响应
- (void)loadView { frame= CGRectMake(20, 80, 280, 50); button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame=frame; [button setTitle:@"OK" forState:UIControlStateNormal]; button.backgroundColor = [UIColor clearColor]; [button addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } -(IBAction)btnClicked:(id)sender { Some codes //删除自身视图 [self.view removeFromSuperview]; //加载子视图 [self.view addSubview:UserViewController.view]; }
三.navigationController
设置nav的initWithRootViewController为自定义视图控制器, 通过pushViewController方法加载其它视图控制器,一般popViewController自动实现--即为左侧按钮. 右侧按钮需要手动添加(NavigationItem.rightBarButtonItem).
nvc = [NumberViewController controllerWithNumber:1]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:nvc]; window.rootViewController = nav;
+ (id) controllerWithNumber: (int) number { NumberViewController *viewController = [[NumberViewController alloc] init]; viewController.number = number; viewController.textView.text = [NSString stringWithFormat:@"Level %d", number]; return viewController; } - (void) pushController: (id) sender { NumberViewController *nvc = [NumberViewController controllerWithNumber:number + 1]; [self.navigationController pushViewController:nvc animated:YES]; } - (void) viewDidAppear: (BOOL) animated { self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR; // match the title to the text view self.title = self.textView.text; self.textView.frame = self.view.frame; // Add a right bar button that pushes a new view if (number < 6) self.navigationItem.rightBarButtonItem = BARBUTTON(@"Push", @selector(pushController:)); }
四.SplitViewController
2022年11月15日 01:22
iOS without Interface Builder is possible, but it requires a lot more work. Without Interface Builder, you have to create your views and layout manually cbd products in code. This can be tedious and time-consuming, but it gives you more control over your app's appearance and behaviour.
2022年12月14日 07:18
There are a few ways to develop iOS apps without using Interface Builder. One way is to use a text editor to edit your storyboard or XIB files. This is a bit more difficult, but it can be done if you're familiar with the XML that makes up these files. Another way is to use a dedicated iOS development environment like AppCode. Délice Breton restaurant This can be a bit more expensive, but it can be worth it if you're doing a lot of iOS development.