using System;
using System.Collections.Generic;
using Foundation;
using UIKit; namespace ddd
{
public partial class ViewController : UIViewController
{
private List<UIImage> collectionData;
private UICollectionView collectionView;
private UICollectionViewFlowLayout collectionViewLayout;
protected ViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
uiConfig(); }
private void uiConfig()
{
//设置假的数据源数组
collectionData = new List<UIImage>();
for (int i = ; i < ; i++)
{
collectionData.Add(UIImage.FromFile("1.jpg"));
}
//初始化UICollectionView
collectionViewLayout = new UICollectionViewFlowLayout();
collectionViewLayout.MinimumLineSpacing = 20f;//设置行距
collectionViewLayout.MinimumInteritemSpacing = 10f;//设置列距
collectionViewLayout.SectionInset = new UIEdgeInsets(, , , );//设置边界
collectionViewLayout.ItemSize = new CoreGraphics.CGSize(70f, 70f);//设置网格大小 collectionView = new UICollectionView(this.View.Bounds, collectionViewLayout);
collectionView.BackgroundColor = UIColor.LightTextColor;
collectionView.RegisterNibForCell(ImageCell.Nib, "ImageCell");
collectionView.Source = new collectionSource(this);
this.View.AddSubview(collectionView);
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
} private class collectionSource : UICollectionViewSource
{
ViewController owner; public collectionSource(ViewController owner)
{
this.owner = owner;
}
//设置网格个数
public override nint GetItemsCount(UICollectionView collectionView, nint section)
{
return owner.collectionData.Count;
}
//设置网格中的内容
public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
{
ImageCell cell = (ImageCell)collectionView.DequeueReusableCell((NSString)ImageCell.Key, indexPath);
cell.ImageView.Image = owner.collectionData[indexPath.Row];
return cell;
}
//选中某一个网格
public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
{
UIAlertView alert = new UIAlertView();
alert.Title = string.Format("你选择了第{0}个网格", indexPath.Row);
alert.AddButton("确定");
alert.Show();
} }
} public partial class ImageCell : UICollectionViewCell
{
public static readonly NSString Key = new NSString("ImageCell");
public static readonly UINib Nib; static ImageCell()
{
Nib = UINib.FromName("ImageCell", NSBundle.MainBundle);
} protected ImageCell(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
this.Initialize(); //调用初始化方法
}
//设置属性
public UIImageView ImageView
{
get;
private set;
}
//初始化
private void Initialize()
{
this.ImageView = new UIImageView(this.ContentView.Bounds); //实例化对象
this.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit; //设置显示模式
this.ContentView.AddSubview(this.ImageView); //添加
} }
}

UICollectionViewCell 网格显示数据的更多相关文章

  1. echarts使用记录(三):x/y轴数据和刻度显示及坐标中网格显示、格式化x/y轴数据

    1.去掉坐标轴刻度线,刻度数据,坐标轴网格,以Y轴为例,同理X轴 xAxis: [{ type: 'category', axisTick: {//决定是否显示坐标刻度 alignWithLabel: ...

  2. mysql数据库导出模型到powerdesigner,PDM图形窗口中显示数据列的中文注释

    1,mysql数据库导出模型到powerdesigner 2,CRL+Shift+X 3,复制以下内容,执行 '******************************************** ...

  3. 怎样操作WebAPI接口(显示数据)

    就在去年Insus.NET已经写好的一个WebAPI项目,并且发布在IIS中.参考<创建与使用Web API>http://www.cnblogs.com/insus/p/5019088. ...

  4. miniui前台无法显示数据

    坑爹,刚开始使用miniui重写对账单的功能,显示数据的时候明明已经获取到json数据了,但前台还是显示不出来,找了一上午的原因,终于找到是因为前台显示字段的field值要改成和json中(数据库字段 ...

  5. EasyUI datagrid 格式化显示数据

    http://blog.163.com/ppy2790@126/blog/static/103242241201512502532379/ 设置formatter属性,是一个函数,格式化函数有3个参数 ...

  6. Flexigrid在IE下不显示数据的处理

    文章总结自我的论坛提问: http://bbs.csdn.net/topics/390498434?page=1#post-394918028 解决方法: 网上的答案经我验证都是不靠谱的,以后大家就知 ...

  7. iPhone Tableview分批显示数据

    //非原创   iPhone Tableview分批显示数据是本文要介绍的内容,主要讲解的是数据的显示.iPhone屏幕尺寸是有限的,如果需要显示的数据很多,可以先数据放到一个table中,先显示10 ...

  8. php 连接mysql数据库并显示数据 实例 转载

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  9. Extjs中Chart利用series的tips属性设置鼠标划过时显示数据

    效果如下: 从官网找到的例子,大家参考下吧.源码: Ext.require('Ext.chart.*'); Ext.require('Ext.layout.container.Fit'); Ext.o ...

随机推荐

  1. 前端css框架SASS使用教程(转)

    一.什么是SASS SASS是一种CSS的开发工具,提供了许多便利的写法,大大节省了设计者的时间,使得CSS的开发,变得简单和可维护. 本文总结了SASS的主要用法.我的目标是,有了这篇文章,日常的一 ...

  2. ArcGIS Engine开发之地图导出

    关于地图导出的方法有很多,但是核心技术就那么一点.下面是从项目实战中总结的一部分地图导出的方法:(以全域导出和区域导出为例) 1.由于地图导出用到的函数和方法容易重复,增加了工作量故首先将其进行封装成 ...

  3. CRM 2013 相关下载 / 2013-10-11

        CRM 2013的安装文件,软件开发工具包(Sdk)以及实施指南,在微软官方网站已经有下载了.     具体地址如下: Name Url 发布日期 语言版本 说明 CRM Server htt ...

  4. 读《乔布斯的NeXT和苹果之间,隔了这两个创业常识》

    原文链接:http://wwww.huxiu.com/article/114950/1.html 前言: 当今硅谷风头最劲的风险投资家马克·安德森曾说,硅谷每年大约诞生15-20家真正值得投资的公司. ...

  5. Oracle 哈希连接原理

    <基于Oracle的sql优化>里关于哈希连接的原理介绍如下: 哈希连接(HASH JOIN)是一种两个表在做表连接时主要依靠哈希运算来得到连接结果集的表连接方法. 在Oracle 7.3 ...

  6. SQL Server查询第31到40条数据

    大致分为两种情况:ID连续和ID不连续. 1.ID连续的情况: 2.ID不连续的情况: (1).两次对表查询,效率较低. ID from A) (2).外层查询没有对表A进行查询,效率提高. ID f ...

  7. Spark编译与打包

    编译打包 Spark支持Maven与SBT两种编译工具,这里使用了Maven进行编译打包: 在执行make-distribution脚本时它会检查本地是否已经存在Maven还有当前Spark所依赖的S ...

  8. getopt,getoptlong学习

         getopt和getoptlong被用来解析命令行参数.   一.getopt #include <unistd.h> extern char *optarg; extern i ...

  9. java正则表达式

    java正则表达式 1.Java正则表达式的语法与示例:  http://baike.xsoftlab.net/view/207.html 2.Java 正则表达式:  http://www.runo ...

  10. CentOS下开启mysql远程连接,远程管理数据库

    当服务器没有运行php.没装phpmyadmin的时候,远程管理mysql就显得有必要了.因为在CentOS下设置的,所以标题加上了CentOS,以下的命令在debian等系统下应该也OK. mysq ...