Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionViewCell Border / Shadow

When building an iPad App, how can you draw a border around a UICollectionViewCell?

More details: I implemented a class ProductCell which extends UICollectionViewCell. Now, I would like to assign some fancy details, e.g. a border, shadow, etc. However, when trying to use something like this here, Xcode tells me that the receiver type 'CALayer' is a forward declaration.

like image 760
itsame69 Avatar asked Oct 29 '12 12:10

itsame69


People also ask

How do I add a shadow to UICollectionViewCell?

Adding a drop shadow to a UICollectionViewCell follows the same method as adding a drop shadow to a UIView . Configure the shadowRadius , shadowOpacity , shadowColor , and shadowOffset of the view's layer property to the desired shadow design.

What is swift Uicollectionview?

An object that manages an ordered collection of data items and presents them using customizable layouts.


1 Answers

Just for a bit more implementation:

#import <QuartzCore/QuartzCore.h> 

in your.m

Make sure your class implements

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;  

as this is where the cell is setup.

You can then change cell.layer.background (only available once quartz is imported)

See below

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {     MyCollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"pressieCell" forIndexPath:indexPath];     //other cell setup here      cell.layer.borderWidth=1.0f;     cell.layer.borderColor=[UIColor blueColor].CGColor;      return cell; } 
like image 161
James Dawson Avatar answered Oct 12 '22 01:10

James Dawson