Permalink
Browse files

Use UIImageView as the background image for default cell.

  • Loading branch information...
1 parent ed37946 commit 906f5e3df9d901762ce366b07144d909faa39be8 @renspr renspr committed Nov 27, 2012
Showing with 11 additions and 1 deletion.
  1. +9 −0 MMGridView/MMGridViewDefaultCell.m
  2. +2 −1 MMGridViewDemo/RootViewController.m
@@ -27,6 +27,7 @@ @implementation MMGridViewDefaultCell
@synthesize textLabel;
@synthesize textLabelBackgroundView;
@synthesize backgroundView;
+@synthesize imageView;
@@ -38,6 +39,10 @@ - (id)initWithFrame:(CGRect)frame
self.backgroundView.backgroundColor = [UIColor lightGrayColor];
[self addSubview:self.backgroundView];
+ // Image view
+ self.imageView = [[UIImageView alloc] initWithFrame:CGRectNull];
+ [self addSubview:self.imageView];
+
// Label
self.textLabelBackgroundView = [[UIView alloc] initWithFrame:CGRectNull];
self.textLabelBackgroundView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
@@ -67,6 +72,10 @@ - (void)layoutSubviews
self.backgroundView.frame = self.bounds;
self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ // Image view
+ self.imageView.frame = self.bounds;
+ self.imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+
// Layout label
self.textLabelBackgroundView.frame = CGRectMake(0,
self.bounds.size.height - labelHeight - inset,
@@ -95,7 +95,8 @@ - (MMGridViewCell *)gridView:(MMGridView *)gridView cellAtIndex:(NSUInteger)inde
{
MMGridViewDefaultCell *cell = [[MMGridViewDefaultCell alloc] initWithFrame:CGRectNull];
cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", index];
- cell.backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell-image.png"]];
+ cell.imageView.image = [UIImage imageNamed:@"cell-image.png"];
+
return cell;
}

0 comments on commit 906f5e3

Please sign in to comment.