You should set the a clear background color in the initWithFrame or/and initWithCoder
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
self.backgroundColor = [UIColor clearColor];
}
return self;
}
the default background of your control will be transparent, and you will then be able to fill any background color in the drawRect if you want.
The reason it doesn't work in your example is that the control have a default black background that is set somewhere ouside the drawRect (probably in the parent UIView init). When you set a colored background, it comes over the black one. When you set a clear one, you see the default black background.