首页 / IOS / IOS项目开发布局三
IOS项目开发布局三
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了IOS项目开发布局三,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2582字,纯文字阅读大概需要4分钟。
内容图文
IOS项目开发布局三
上次讲到项目文件夹的模版,下面我开始以侧边栏为例,继续讲框架。
首先看文件的结构布局图如下:
1. 在Libs的SlideViewController文件夹下添加侧边栏第三方文件
2. 使用侧边栏代码在DemAppDelegate中添加如下:(主要代码)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
SLVMainViewController *mainViewController = [[SLVMainViewController alloc] init];
mainViewController.view.backgroundColor = [UIColor greenColor];
self.sideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:mainViewController];
self.sideViewController.delegate = self;
[mainViewController release];
self.window.rootViewController = self.sideViewController;
[self.window makeKeyAndVisible];
return YES;
}
3. 在Constants文件中定义一些全局的宏4. DemViewController.h和DemViewController.m 是所有ViewController的基类,在里面可以添加一些公用的代码
代码片段如下:
- (id)init
{
if (self = [super init]) {
if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) {
[self setAutomaticallyAdjustsScrollViewInsets:NO];
}
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
}
return self;
}
说明如下:
在init方法中添加的代码是为了适配IOS7和IOS7以前的版本,因为IOS7的视图会占用状态栏。
5. 在DemMainViewController中添加需要注意的代码如下
- (void)addMainController
{
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [UIColor blueColor];
viewController.title = @"主页面";
viewController.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(showLeftController)];
UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
contentLabel.center = CGPointMake(viewController.view.bounds.size.width/2, (viewController.view.bounds.size.height - 64)/2);
contentLabel.text = @"主视图";
contentLabel.textColor = [UIColor redColor];
contentLabel.backgroundColor = [UIColor clearColor];
contentLabel.font = [UIFont systemFontOfSize:30.f];
[viewController.view addSubview:contentLabel];
[contentLabel release];
_mainNavController = [[UINavigationController alloc] initWithRootViewController:viewController];
[_mainNavController.view setFrame:self.view.bounds];
[viewController release];
[self.view addSubview:_mainNavController.view];
}
说明:注意红色部分的代码,如果不添加这一行代码,导航栏视图会下移20个像素
6. 运行的效果图如下:
IOS6系统的运行图
IOS7系统的运行图
提供项目工程的下载地址如下:http://download.csdn.net/detail/chchong1234/6979661
原文:http://blog.csdn.net/chchong1234/article/details/20224467
内容总结
以上是互联网集市为您收集整理的IOS项目开发布局三全部内容,希望文章能够帮你解决IOS项目开发布局三所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。