Graphics Reference
In-Depth Information
index
inSection
:
0
];
UICollectionViewCell
*cell =
[
self
.
collectionView
cellForItemAtIndexPath
:indexPath];
UIImageView
*imageView = [cell.
contentView
.
subviews
lastObject
];
imageView.
image
= image;
});
});
//not loaded yet
return
nil
;
}
- (
UICollectionViewCell
*)collectionView:(
UICollectionView
*)collectionView
cellForItemAtIndexPath:(
NSIndexPath
*)indexPath
{
//dequeue cell
UICollectionViewCell
*cell =
[collectionView
dequeueReusableCellWithReuseIdentifier
:@"Cell"
forIndexPath
:indexPath];
//add image view
UIImageView
*imageView = [cell.
contentView
.
subviews
lastObject
];
if
(!imageView)
{
imageView = [[
UIImageView
alloc
]
initWithFrame
:
cell.
contentView
.
bounds
];
imageView.
contentMode
=
UIViewContentModeScaleAspectFit
;
[cell.
contentView
addSubview
:imageView];
}
//set or load image for this index
imageView.
image
= [
self
loadImageAtIndex
:indexPath.
item
];
//preload image for previous and next index
if
(indexPath.
item
< [
self
.
imagePaths
count
] -
1
)
{
[
self
loadImageAtIndex
:indexPath.
item
+
1
];
}
if
(indexPath.
item
>
0
)
{
[
self
loadImageAtIndex
:indexPath.
item
-
1
];
}