UICollectionViewCell 网格显示数据
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 网格显示数据的更多相关文章
- echarts使用记录(三):x/y轴数据和刻度显示及坐标中网格显示、格式化x/y轴数据
1.去掉坐标轴刻度线,刻度数据,坐标轴网格,以Y轴为例,同理X轴 xAxis: [{ type: 'category', axisTick: {//决定是否显示坐标刻度 alignWithLabel: ...
- mysql数据库导出模型到powerdesigner,PDM图形窗口中显示数据列的中文注释
1,mysql数据库导出模型到powerdesigner 2,CRL+Shift+X 3,复制以下内容,执行 '******************************************** ...
- 怎样操作WebAPI接口(显示数据)
就在去年Insus.NET已经写好的一个WebAPI项目,并且发布在IIS中.参考<创建与使用Web API>http://www.cnblogs.com/insus/p/5019088. ...
- miniui前台无法显示数据
坑爹,刚开始使用miniui重写对账单的功能,显示数据的时候明明已经获取到json数据了,但前台还是显示不出来,找了一上午的原因,终于找到是因为前台显示字段的field值要改成和json中(数据库字段 ...
- EasyUI datagrid 格式化显示数据
http://blog.163.com/ppy2790@126/blog/static/103242241201512502532379/ 设置formatter属性,是一个函数,格式化函数有3个参数 ...
- Flexigrid在IE下不显示数据的处理
文章总结自我的论坛提问: http://bbs.csdn.net/topics/390498434?page=1#post-394918028 解决方法: 网上的答案经我验证都是不靠谱的,以后大家就知 ...
- iPhone Tableview分批显示数据
//非原创 iPhone Tableview分批显示数据是本文要介绍的内容,主要讲解的是数据的显示.iPhone屏幕尺寸是有限的,如果需要显示的数据很多,可以先数据放到一个table中,先显示10 ...
- php 连接mysql数据库并显示数据 实例 转载
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- Extjs中Chart利用series的tips属性设置鼠标划过时显示数据
效果如下: 从官网找到的例子,大家参考下吧.源码: Ext.require('Ext.chart.*'); Ext.require('Ext.layout.container.Fit'); Ext.o ...
随机推荐
- 应用Apache Axis进行Web Service开发
转自(http://tscjsj.blog.51cto.com/412451/84813) 一.概述 SOAP原意为Simple Object Access Protocol(简单对象访问协议),是一 ...
- SDK接入(1)之Android Facebook SDK接入
SDK接入(1)之Android Facebook SDK接入 由于游戏已上线,且处于维护阶段,所以有空写写各种SDK接入过程和遇到的问题,也当作一种工作总结.SDK接入主流分为这么几类,登录.支付. ...
- 安开发卓之Notification(一)代码直接能用
Notification是Android中很理想的一种显示提示信息的方法,它可以将应用程序的信息传递到我们的Android桌面状态栏,采用这种消息传递方式不会影响到用户对手机的正常使用.而且Notif ...
- MVC下压缩输入的HTML内容
在MVC下如何压缩输出的HTML代码,替换HTML代码中的空白,换行符等字符? 1.首先要了解MVC是如何输出HTML代码到客户端的,先了解下Controller这个类,里面有很多方法,我们需要的主要 ...
- 在DBeaver中phoenix查询报错:org.apache.phoenix.exception.PhoenixIOException: The system cannot find the path specified
环境:Phoenix:4.4,win7系统 问题:Phoenix在查询hbase时,报"系统找不到指定路径". 解决: 请参见 https://distcp.quora.com/C ...
- 二进制包安装MySQL数据库
1.1二进制包安装MySQL数据库 1.1.1 安装前准备(规范) [root@Mysql_server ~]# mkdir -p /home/zhurui/tools ##创建指定工具包存放路径 [ ...
- 记一次简单的SQL优化
原来的sql是这样写的 SELECT d.ONSALE_BARCODE, d.ONSALE_NAME, c.ONSALE_ID, CAST( , ) ) AS CUSTOMARY_PRICE, CAS ...
- AD域撤销域用户管理员权限方案
一.简介 公司大部分主机加入域已有一段时间了,由于某软件没管理员权限不能执行,所以管理员权限一直没撤销,不能完全实现域的管理效果.但起码实现了域用户脱离不了域的控制:http://www.cnblog ...
- 最新官方WIN10系统32位,64位系统ghost版下载
系统来自:系统妈 随着Windows 10Build 10074 Insider Preview版发布,有理由相信,Win10离最终RTM阶段已经不远了.看来稍早前传闻的合作伙伴透露微软将在7月底正式 ...
- windows中,端口查看&关闭进程及Kill使用
测试过程中遇到的问题,杂记一: 1.netstat -ano | findstr "8001" 查看端口8001被哪个进程占用:由下图可以看出,被进程为3736的占用 2.查 ...