kolinkrewinkel/KKGridView — Issue #87: Can't create grid cells with rounded corners
Author: adamvduke
Created: 2011-12-29 06:14:27+00:00
State: open

Is there a recommended way to draw a grid cell with rounded corners? I have tried a number of different things and nothing seems to have any effect. Below is what I've tried. The grid view shows up fine and everything looks good, except I can't figure out how to round the corners of the cells.

Loading the grid view

_gridView = [[KKGridView alloc] initWithFrame:CGRectZero];
_gridView.dataSource = self;
_gridView.cellSize = CGSizeMake(75.f, 70.f);
_gridView.cellPadding = CGSizeMake(4.f, 4.f);
_gridView.scrollsToTop = YES;
_gridView.backgroundColor = TTSTYLEVAR(facebookBlue);
_gridView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

Laying out the grid view

_gridView.frame = CGRectMake(0, 0, 320, 372);

Grid view datasource methods

- (NSUInteger)gridView:(KKGridView *)gridView numberOfItemsInSection:(NSUInteger)section
{
return 200;
}

- (KKGridViewCell *)gridView:(KKGridView *)gridView cellForItemAtIndexPath:(KKIndexPath *)indexPath
{
KKGridViewCell *cell = [KKGridViewCell cellForGridView:gridView];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:cell.frame];

UIImage *image;

NSUInteger index = indexPath.index;
if(index % 2 == 0)
{
image = [UIImage imageNamed:@"twitter.jpeg"];
}
else
{
image = [UIImage imageNamed:@"photo.JPG"];
}

imageView.image = image;

imageView.backgroundColor = [UIColor clearColor];
imageView.layer.cornerRadius = 10;
imageView.layer.masksToBounds = NO;

cell.backgroundColor = [UIColor clearColor];
cell.layer.cornerRadius = 10;
cell.layer.masksToBounds = NO;

cell.contentView.backgroundColor = [UIColor clearColor];
cell.contentView.layer.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.5].CGColor;
cell.contentView.layer.cornerRadius = 10;
cell.contentView.layer.masksToBounds = NO;

[cell.contentView addSubview:imageView];
if(index % 3 == 0)
{
cell.accessoryType = KKGridViewCellAccessoryTypeBadgeExclamatory;
}
if(index % 3 == 0 && index % 5 == 0)
{
cell.accessoryPosition = KKGridViewCellAccessoryPositionBottomRight;
}

return cell;
}