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. 深入理解javascript函数参数与闭包(一)

    在看此文章,希望先阅读关于函数基础内容 函数定义与函数作用域 的章节,因为这篇文章或多或少会涉及函数基础的内容,而基础内容,我放在函数定义函数作用域 章节. 本文直接赘述函数参数与闭包,若涉及相关知识 ...

  2. 使用WebRTC搭建前端视频聊天室——数据通道篇

    本文翻译自WebRTC data channels 在两个浏览器中,为聊天.游戏.或是文件传输等需求发送信息是十分复杂的.通常情况下,我们需要建立一台服务器来转发数据,当然规模比较大的情况下,会扩展成 ...

  3. TextField和TextView的限制输入长度

    TextField的限制代理方法 只需要在这个代理方法里面code这样的代码就可以了 16 是长度可以自己设置 - (BOOL)textField:(UITextField *)textField s ...

  4. Struts2初始(一)

    1.过滤器:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter位置:在struts2的核心包struts2-co ...

  5. MYSQL基础操作之单表的增删改查

    一.添加数据. -- 1.创建表,并插入一定的数据. CREATE TABLE STUDENT( ID INT, USERNAME ), SERVLET INT, JSP INT, ADDRESS ) ...

  6. jqgrid+bootstrap样式实践

    jqgrid+bootstrap样式实践,报错数据加载,选中,删除等功能 需要引入的样式 bootstrap.min.css ui.jqgrid.css 需要引入的JS jquery.min.js b ...

  7. order by 与 group by 区别

    order by 排序查询.asc升序.desc降序 示例: select * from 学生表 order by 年龄 ---查询学生表信息.按年龄的升序(默认.可缺省.从低到高)排列显示 也可以多 ...

  8. STM32C8T6 JTAG使用到PB3|PB4|PA13|PA14|PB15端口做普通IO时,需禁止JTAG!

    GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIO ...

  9. HDOJ 1008. Elevator 简单模拟水题

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  10. Month Scheme

    新的一个月,我要给自己立FLAG了, ABCDEFG HIJKLMN 天下事有难易乎,为之,则难者亦易矣,不为,则易者亦难矣. 这次采取的策略是,每完成一项work回来补充内容.希望能把这篇blog补 ...