tags:

views:

405

answers:

1

Hi,

I am trying to create a grid view by using a UITableView (my older questions have pointed me in this direction) and am currently setting up the views for the individual items. Having created a custom UITableViewCell that displays 3 items per row, I have decided to pull these items into a subclass of UIView called ItemView.

This ItemView will then be added as a subview to the custom UITableViewCell to display the grid. Anyway, I have managed to create the view and can get it to display a UILabel fine, however I am having trouble in changing ItemView to be transparent apart from the UIViews (Labels, buttons, images etc) within it. Here is my code for the UIView:

#import <UIKit/UIKit.h>
@interface ItemView : UIView {
}
@end

//

#import "ItemView.h"
@implementation ItemView

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
  [self setBackgroundColor:[UIColor lightGrayColor]];
}

- (void)dealloc {
  [super dealloc];
}
@end

Where should I set the background color for it to work properly?

Cheers

+3  A: 

Try:

self.backgroundColor = [UIColor clearColor];

I don't see any reason not to have that in your init method. I don't think you want to override drawRect: in this case as you'll need to draw the entire view yourself.

Rob Jones
I had tried this, however after having looked through the rest of my code, I found a load of things that were messing it up. Finally got it working. Thanks for the response.
Jack