iOS的图表显示的实现
在app通常有家居展览的照片,显示广告。或者头条新闻。通常网易新闻client
如图,红框框的位置就是一个典型的图展,
熟悉iOS的人肯定知道,这个是个UIScrollview,里面加几张图片就可以实现,当然以下的三个小点点也是不可缺少的。
那做这个东西的思路就非常明晰了:首先这个类是个scrollview,然后在这个scrollview中加入imageview。然后给每一个imageview加入对应的事件就可以。
源码例如以下:
头文件:
//
// GalleryView.h
// Pitch
//
// Created by zhujinhui on 14-9-1.
// Copyright (c) 2014年 zhujinhui. All rights reserved.
// #import <UIKit/UIKit.h> /**
* the protocol of the gallery
*/
@protocol GalleryDelegate <NSObject> -(void)galleryViewItemDidClicked:(int)index; @end /** gallery is used to show a lot of images */ @interface GalleryView : UIScrollView @property (assign ,nonatomic) id<GalleryDelegate> mDelegate; /**
* set all the image to gallery
*/
-(void)setData:(NSArray *) data; @end
实现文件:
//
// GalleryView.m
// Pitch
//
// Created by zhujinhui on 14-9-1.
// Copyright (c) 2014年 zhujinhui. All rights reserved.
// #import "GalleryView.h" #define TAG_BTN_OFFSET 12345 @implementation GalleryView - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} /**
* set all the image to gallery
*/
-(void)setData:(NSArray *) data{
//if data is not a array of string,it will throw exception
@try {
//remove all the subview from gallery view
for (UIView *view in self.subviews) {
[view removeFromSuperview];
} //add view to gallery
for (int index = 0; index < [data count]; ++index) {
NSString *imageName = data[index];
UIImage *img = [UIImage imageNamed:imageName];
UIImageView *imgv = [[UIImageView alloc]initWithImage:img];
CGRect frame = CGRectMake(index * 320, 0, 320, 150);
[imgv setFrame:frame];
//add gesture to image
imgv.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]init];
[tapGestureRecognizer addTarget:self action:@selector(tapped:)];
[imgv addGestureRecognizer:tapGestureRecognizer]; //set tag
imgv.tag = TAG_BTN_OFFSET + index;
[self addSubview:imgv]; } }
@catch (NSException *exception) {
NSLog(@"%@",exception);
}
} -(BOOL)tapped:(UIGestureRecognizer *)gestureRecognizer{
//force convert index to integer
int index = (int) (gestureRecognizer.view.tag - TAG_BTN_OFFSET); if (self.mDelegate) {
if ([self.mDelegate respondsToSelector:@selector(galleryViewItemDidClicked:)]) {
[self.mDelegate galleryViewItemDidClicked:index];
}
}else{
NSLog(@"please set delegate");
} return TRUE;
} -(void)awakeFromNib{ } /*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/ @end
iOS的图表显示的实现的更多相关文章
- storyboard在ios模拟器无法显示的问题
一.问题描述 1.在原有项目新建一个名称为test的storyboard类型的文件. 2.test.storyboard添加View Controller,并设置View Controller下Vie ...
- aChartEngine图表显示(一页显示多张图表)
在看本篇的时候,请确认已经看过了 某android平板项目开发笔记----aChartEngine图表显示(1) 不然,有些地方这里就不再说明… 关于XYMutilpleSeriesDataset 一 ...
- 使用Visifire+ArcGIS API for Silverlight实现Graphic信息的动态图表显示
原文:使用Visifire+ArcGIS API for Silverlight实现Graphic信息的动态图表显示 首先来看一看实现的效果: PS:原始的程序中更新曲线数据时添加了过渡的效果,具体可 ...
- 关于FusionCharts图表宽度width的设置问题导致图表显示异常的解决办法
关于FusionCharts图表宽度width的设置问题导致图表显示异常的解决办法 题设: 经常使用FusionCharts图表的朋友可能会遇到这个问题.就是在FusionCharts显示的时候有时候 ...
- 解决微信小程序的wx-charts插件tab切换时的显示会出现位置移动问题-tab切换时,图表显示错乱-实现滑动tab
解决Echarts在微信小程序tab切换时的显示会出现位置移动问题 tab切换时,图表显示错乱 <canvas class="kcanvas" canvas-id=" ...
- 在Bootstrap开发中解决Tab标签页切换图表显示问题
在做响应式页面的时候,往往需要考虑更多尺寸设备的界面兼容性,一般不能写死像素,以便能够使得界面元素能够根据设备的不同进行动态调整,但往往有时候还是碰到一些问题,如Tab标签第一页面正常显示,但是切换其 ...
- Xamarin iOS教程之显示和编辑文本
Xamarin iOS教程之显示和编辑文本 Xamarin iOS显示和编辑文本 在一个应用程序中,文字是非常重要的.它就是这些不会说话的设备的嘴巴.通过这些文字,可以很清楚的指定这些应用程序要表达的 ...
- 关于asp.net mvc中 weiui gallery中IOS 下不显示预览图片问题的解决方式
IOS 下面不显示预览. 结果去掉了红框中的缓存部分 就可以显示了 备忘,也帮助一下需要的朋友 @*<meta http-equiv="pragma" content=&qu ...
- 搭建自己的博客(十七):添加每日阅读量并使用highcharts通过图表显示
之前写了单篇博客的阅读量统计,今天添加了博客总阅读量统计,并且使用highcharts图表显示. 1.变化的部分
随机推荐
- HDU 5009 Paint Pearls (动态规划)
Paint Pearls Problem Description Lee has a string of n pearls. In the beginning, all the pearls have ...
- 黑马程序猿————OC在Foundation框架结构和字符串
------<a href="http://www.itheima.com" target="blank">Java火车.Android火车.iOS ...
- SE 2014年4月25日
1. 描述 STP 的计算过程 (1.根桥的选举 2.端口角色的确定) 根桥的选举 启用STP后,网络中桥ID最小的交换机会被选为根桥,桥ID由桥优先级和桥MAC两部分组成,优先级默认为32768,首 ...
- SAE微信公众号PHP SDK, token一直验证失败
用的是SAE,创建的是微信公众号PHP SDK框架,里面example文件夹下有server.php用来验证token的.但是问题来了,无论我怎么输入URL和token,一直告诉我token验证失败. ...
- JsonCpp Documentation
JsonCpp - JSON data format manipulation library JsonCpp Documentation 0.6.0-rc2 Introduction JSON (J ...
- Learning Cocos2d-x for WP8(3)——文字篇
原文:Learning Cocos2d-x for WP8(3)--文字篇 C#兄弟篇Learning Cocos2d-x for XNA(3)——文字篇 文字,是人类文明的象征. 文字显示,可用字符 ...
- TCP closing a connection
client closes socket: clientSocket.close(); step1 :client sends TCP FIN control segment to server st ...
- js创建下载文件
function downloadFile(fileName, content){ var aLink = document.createElement('a'); var blob = new Bl ...
- java 常用的包 默认导入的包
1.java.lang----包含一些Java语言的核心类,如String.Math.Integer.System和Thread,提供常用功能. 2.java.awt----包含了构成抽象窗口工具集( ...
- linux动态库编译和使用
linux动态库编译和使用详细剖析 引言 重点讲述linux上使用gcc编译动态库的一些操作.并且对其深入的案例分析.最后介绍一下动态库插件技术, 让代码向后兼容.关于linux上使用gcc基础编译, ...