Where do you call createRect
? That is not a UIView
method and will never get called on its own. Did you mean to use drawRect:
instead?
Also, is there a reason you made a custom initializer and didn't just override initWithFrame:
? You are seemingly accomplishing the same thing in a needlessly complicated way.
EDIT: I see what is happening now. You are calling it when calling the super initializer. Have you tried converting it to drawRect: Instead? As it is now you are attempting to perform drawing before the view is even on the screen.
Here is an example that should work just fine:
#import "Block.h"
@implementation Block
-(id)initWithFrame:(CGRect)frame
{
if(self = [super initWithFrame:frame])
{
// put any extra customization here, although your example doesn't require any
}
return self;
}
-(void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextFillRect(context, rect);
}
@end