continuous

Open full view…

PhotosKit

hsupengjun
Mon, 11 Jul 2016 02:17:28 GMT

Anyone got this to work?

hsupengjun
Mon, 11 Jul 2016 02:18:12 GMT

using System; using System.Collections.Generic; using System.Linq; using Foundation; using UIKit; using CoreGraphics; using Photos; class AlbumCollectionViewController : UICollectionViewController { public AlbumCollectionViewController(UICollectionViewLayout layout) : base(layout) { CollectionView.RegisterClassForCell( typeof(UICollectionViewCell), "Cell" ); var layoutDelegate = new CustomFlowLayoutDelegate() as UICollectionViewDelegateFlowLayout; // CollectionView.Delegate = layoutDelegate; CollectionView.BackgroundColor = UIColor.Gray; } public override nint GetItemsCount(UICollectionView collectionView, nint section) { return 100; } public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) { var cell = CollectionView.DequeueReusableCell("Cell", indexPath) as UICollectionViewCell; if (cell.ContentView.Subviews.Length == 0) { // Add Subview Here cell.ContentView.AddSubview( new UILabel() ); cell.ContentView.AddSubview( new UIImageView() ); } // Confugure View cell.ContentView.BackgroundColor = UIColor.Black; // Configure Your Subview var label = cell.ContentView.Subviews[0] as UILabel; var imageView = cell.ContentView.Subviews[1] as UIImageView; label.Frame = new CGRect(10.0f, 80.0, 60.0, 20.0f); label.Lines = 0; label.Font = label.Font.WithSize(8.0f); label.TextColor = UIColor.White; label.TextAlignment = UITextAlignment.Center; label.Text = "Heeeeelllllo!"; imageView.BackgroundColor = UIColor.Black; imageView.Frame = new CGRect(0.0f, 0.0f, 80.0f, 80.0f); imageView.Image = RandomPhoto(); return cell; } private UIImage RandomPhoto() { PHFetchResult all = PHAsset.FetchAssets(PHAssetMediaType.Image, null); var i = new Random().Next(Int32.Parse(all.Count.ToString())); var asset = all.ObjectAt(i) as PHAsset; var name = asset.LocalIdentifier; var size = new CGSize(160.0f, 160.0f); var manager = PHImageManager.DefaultManager; var options = new PHImageRequestOptions(); var result = new UIImage(); options.Synchronous = true; manager.RequestImageForAsset(asset, size, PHImageContentMode.AspectFill, options, (image, metadata) => { result = image; }); return result; } } class CustomFlowLayoutDelegate : UICollectionViewDelegateFlowLayout { public CustomFlowLayoutDelegate() : base() {} public override CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath) { Console.Write("Called"); // collectionView:layout:sizeForItemAtIndexPath: return new CGSize(100.0f, 50.0f); } } var layout = new UICollectionViewFlowLayout(); layout.ItemSize = new CGSize(80.0f, 100.0); var Main = new AlbumCollectionViewController(layout);