Color UIView Color

I'm trying to create a grid view using a UITableView (my old questions pointed me in that direction), and I'm currently setting up views for individual elements. Having created a custom UITableViewCell that displays 3 items in a row, I decided to output these items to a UIView subclass called ItemView.

This ItemView will be added as a subheading to the custom UITableViewCell to display the grid. In any case, I managed to create a view and get it to display UILabel fine, however, I had problems changing the ItemView so that it was transparent, in addition to UIViews (shortcuts, buttons, images, etc.) inside it. Here is my code for 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 the correct operation?

Greetings

+5
1

Try:

self.backgroundColor = [UIColor clearColor];

, init. , drawRect: .

+11

All Articles