• 简介
  • 效果展示
  • 思路分析
  • 代码实现
  • Git地址

一、简介

某些公司有较多的产品时,通常会在一个产品中推广另外的一些产品,我简单的封装了一个UIControllerView,由于不同公司,要求不同。所以大家可以根据自己不同的需求来改里面的内容,希望对大家有用。

我这里解压网易的资源文件,获取到的数据。(如有任何问题,联系本人372623326@qq.com)


二、效果展示

因为我的截图都是使用的模拟器,所以后面都显示的下载图标。如果用真机会根据用户是否下载了对应的应用来判断显示什么样的图片,以及用户之后点击究竟跳转到App Store还是打开应用。(大家可自己测试,后面会放代码)


三、思路分析

网易的资源是json本地文件,里面有所以的资源,已经打开对应的应用的URL和下载应用的URL。我们在显示的时候,只需要根据模型数据,来决定显示就好了


四、代码实现

1⃣️第一个页面的代码实现((.m文件)主要是改变导航条的一些代码,真正用到的时候,只需要告诉第二个页面,json文件的名称就可以了)

#import "MainViewController.h"
#import "ProjectModel.h"
#import "ViewController.h" #define iOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) @interface MainViewController ()
{
NSArray *_projectData;
}
@end @implementation MainViewController + (void)initialize
{
// 1.取出设置主题的对象
UINavigationBar *navBar = [UINavigationBar appearance];
UIBarButtonItem *barItem = [UIBarButtonItem appearance]; // 2.设置导航栏的背景图片
NSString *navBarBg = nil;
if (iOS7) { // iOS7
navBarBg = @"NavBar64"; // 设置导航栏的渐变色为白色(iOS7中返回箭头的颜色变为这个颜色:白色)
navBar.tintColor = [UIColor whiteColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
} else { // 非iOS7
navBarBg = @"NavBar";
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque; // 设置导航栏按钮的背景图片
[barItem setBackgroundImage:[UIImage imageNamed:@"NavButton"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barItem setBackgroundImage:[UIImage imageNamed:@"NavButtonPressed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault]; // 设置导航栏返回按钮的背景图片
[barItem setBackButtonBackgroundImage:[UIImage imageNamed:@"NavBackButton"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barItem setBackButtonBackgroundImage:[UIImage imageNamed:@"NavBackButtonPressed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
} [navBar setBackgroundImage:[UIImage imageNamed:navBarBg] forBarMetrics:UIBarMetricsDefault]; // 3.设置导航栏标题颜色为白色
[navBar setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor whiteColor]
}]; // 4.设置导航栏按钮文字颜色为白色
[barItem setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor whiteColor],
UITextAttributeFont : [UIFont systemFontOfSize:]
} forState:UIControlStateNormal]; } - (void)viewDidLoad {
[super viewDidLoad]; self.title = @"主页";
[self addRecommendBtn];
} - (void)addRecommendBtn
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(, , , );
[btn setTitle:@"网易推荐应用" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize:14.0];
[btn addTarget:self action:@selector(recommendClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn];
} - (void)recommendClick
{
ViewController *viewController = [[ViewController alloc] init];
viewController.jsonString = @"more_project.json"; [self.navigationController pushViewController:viewController animated:YES];
}

2⃣️推荐页面的实现(.m文件)

#import "ViewController.h"
#import "ProjectCell.h"
#import "ProjectModel.h" @interface ViewController ()
{
NSArray *_projectData;
}
@end @implementation ViewController - (void)setJsonString:(NSString *)jsonString
{
NSString *path = [[NSBundle mainBundle] pathForResource:jsonString ofType:nil];
NSData *data = [NSData dataWithContentsOfFile:path];
NSError *error;
NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; NSMutableArray *tempArray = [NSMutableArray array];
for (NSDictionary *dict in array) {
ProjectModel *p = [ProjectModel ProjectWithDict:dict];
p.everDownload = [[UIApplication sharedApplication] canOpenURL:[self getUrl:p.customUrl]];
[tempArray addObject:p];
}
_projectData = tempArray;
} - (NSURL *)getUrl:(NSString *)url
{
NSString *urlStr = [NSString stringWithFormat:@"%@://", url];
return [NSURL URLWithString:urlStr];
} - (void)viewDidLoad {
[super viewDidLoad]; self.navigationController.navigationBar.translucent = NO; self.title = @"推荐应用";
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.allowsSelection = NO;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _projectData.count;
} - (ProjectCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
ProjectCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) {
cell = [[ProjectCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
} cell.project = _projectData[indexPath.row];
return cell;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
} @end

3⃣️ cell的实现文件(.m文件)

#import "ProjectCell.h"

#define kIconW 54
#define kIconH 54 #define kPadding 10 #define kBtnW 40
#define kBtnH 40 @interface ProjectCell()
{
UIButton *_controlBtn; BOOL _canOpen;
}
@end @implementation ProjectCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.center = CGPointMake(self.frame.size.width - kBtnW * 0.5 - kPadding, self.frame.size.height * 0.5 + kPadding);
btn.bounds = CGRectMake(, , kBtnW, kBtnH);
[btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
_controlBtn = btn;
[self.contentView addSubview:btn];
} return self;
} - (void)btnClick
{
if (_canOpen) {
[[UIApplication sharedApplication] openURL:[self getUrl:_project.customUrl]];
} else {
[[UIApplication sharedApplication] openURL:[self getUrl:_project.url]];
}
} - (void)setProject:(ProjectModel *)project
{
_project = project;
_canOpen = project.isEverDownload; self.imageView.image = [UIImage imageNamed:project.icon];
self.textLabel.text = project.title;
self.detailTextLabel.text = project.stitle; if (project.isEverDownload) {
[_controlBtn setImage:[UIImage imageNamed:@"appadcell_openbutton"] forState:UIControlStateNormal];
} else {
[_controlBtn setImage:[UIImage imageNamed:@"appadcell_downloadbutton"] forState:UIControlStateNormal];
}
} - (NSURL *)getUrl:(NSString *)url
{
NSString *urlStr = [NSString stringWithFormat:@"%@://", url];
return [NSURL URLWithString:urlStr];
} - (void)layoutSubviews
{
[super layoutSubviews]; CGFloat cellH = self.frame.size.height;
self.imageView.frame = CGRectMake(cellH - kIconW, (cellH - kIconH) * 0.5, kIconW, kIconH);
self.imageView.contentMode = UIViewContentModeScaleAspectFit; CGRect oldLabelFrame = self.textLabel.frame;
oldLabelFrame.origin.x = CGRectGetMaxX(self.imageView.frame) + kPadding;
self.textLabel.frame = oldLabelFrame; CGRect oldDetailLabelFrame = self.detailTextLabel.frame;
oldDetailLabelFrame.origin.x = oldLabelFrame.origin.x;
self.detailTextLabel.frame = oldDetailLabelFrame;
} @end

五、Git下载地址

(后续更新上去https://github.com/wangzi9521

iOS项目开发之仿网易彩票推荐应用的更多相关文章

  1. iOS项目开发常用功能静态库

    YHDeveloperTools iOS项目开发常用功能静态库 查看源码 功能方法: 1.字符检查 [NSString checkStringWithType:Email andTargetStrin ...

  2. iOS项目开发实战——学会使用TableView列表控件(四)plist读取与Section显示

    文本将会实现把数据存储到plist文件里.然后在程序中进行读取.在TableView控件中依据不同的类别显示Section. 有关TableView 的其它实现,请參考<iOS项目开发实战--学 ...

  3. 聚合数据 iOS 项目开发实战:条码查询器

    记录下,聚合数据 iOS 项目开发实战:条码查询器:视频地址:http://www.jikexueyuan.com/course/324.html 条码查询API:https://www.juhe.c ...

  4. ios项目开发汇总

    UI界面 iOS和Android 界面设计尺寸规范  http://www.alibuybuy.com/posts/85486.html iPhone app界面设计尺寸规范  http://www. ...

  5. iOS项目开发优秀文章汇总

    UI界面 iOS和Android 界面设计尺寸规范  http://www.alibuybuy.com/posts/85486.html iPhone app界面设计尺寸规范  http://www. ...

  6. iOS项目开发实战——使用CoreLocation获取当前位置信息

    随着基于位置服务LBS和移动互联网的兴起,你的位置是越来越重要的一个信息.位置服务已经是当前的热门应用如微信.陌陌等社交应用的杀手锏.而在iOS开发中,苹果已经给我们提供了一个位置接口.CoreLoc ...

  7. iOS项目开发实战——通过Http Get方式与server通信

    移动client往往须要同后台server进行通信,上传或者下载数据,最经常使用到的方式就是Http Get,如今我们来学习在iOS项目中使用Get方式同server进行通信. [一]server端实 ...

  8. iOS项目开发实战——iOS网络编程获取网页Html源码

    现在我们身处互联网的时代.不论什么一个软件或是App,都会或多或少与网络打交道,并不断发生数据交互.一个没有涉及网络编程的应用会显得比較low,这里我们将会開始使用Swift开发iOS应用,而且主要来 ...

  9. iOS项目开发实战——plist数组解析

    plist数据是苹果公司创造的数据格式,基于XML,因为在iOS,Mac系统中操作plist很方便,所以我们经常会用到.在iOS项目中.系统会自己主动生成一个Info.plist文件,里面存放了iOS ...

随机推荐

  1. android hook 框架 libinject2 简介、编译、运行

    Android so注入-libinject2 简介.编译.运行 Android so注入-libinject2  如何实现so注入 Android so注入-Libinject 如何实现so注入 A ...

  2. 資料視覺化:使用Python與JavaScript 简介和目录

    內容簡介 學習如何運用Python與JavaScript這組對超級強大的組合,處理手中的原始資料,建構出功能強大的互動式視覺化網站.在這一本以實務為主的書中,將告訴您如何善用Python和JavaSc ...

  3. cp2102通过GPIO连接树莓派

    此博客不在更新,我的博客新地址:www.liuquanhao.com ----------------------------------------------------------------- ...

  4. 在线查看PDF文档

    http://www.cnblogs.com/morang/p/4598894.html http://78re52.com1.z0.glb.clouddn.com/resource%2Fscenar ...

  5. 树莓派3b入门教程

    原文地址:传送门 这篇教程将带您一起玩转树莓派3(Raspberry Pi 3).和普通PC一样,拿到新设备第一件事就是要给它安装一个操作系统,并做一些初始化的操作.比PC简单的是,树莓派是一个固定配 ...

  6. phpcms编辑器添加一键排版控件

    CKEditor添加一键排版插件实例,大家都知道phpcms也是ckeditor编辑器,那么如果增加这个一键排版这个牛逼功能呢增加好了后,效果图是这样的 废话不多说,直接说步骤第一步:config.j ...

  7. Apache优化建议

    Apache是Web服务器软件,它最常见是搭配PHP开发语言去使用.今天,小编根据Apache官方手册再结合实际,整理出下面这些优化建议,希望对大家的Apache服务器的运行效率有效果. 1.控制Ma ...

  8. Mybatis中的XML中需要用到的转义符号整理

    使用这么久的Mybatis中需要转义的符号整理一下,小结一下: 1.       <         小于符号        < 2.       <=       小于等于     ...

  9. Flash3D学习计划(三)——学习VB,IB相关,理解三角形顶点顺序;在屏幕上显示2D矩形,并实现缩放,平移,旋转

    VB:顶点缓冲 IB: 顶点索引缓冲 三角形的顶点顺序决定了三角形是顺时针还是逆时针,从而决定了三角形在背面剔除的过程中是否会被剔除掉. 相关理论知识可以在前面的文章中找到更多的说明. 实现效果 sf ...

  10. linux mysql cluser集群

    管理节点的安装与启动 config.init内容如下 [NDBD DEFAULT] NoOfReplicas=1 #定义在Cluster环境中相同数据的份数,最大为4 [NDB_MGMD] #设置管理 ...