UILabel in drawRect does not draw
quick question, I got this drawRect
method in the a UIView
with a UILabel
and circle.The circle is drawn correctly but the UILabel
is not.
Any 开发者_如何学编程ideas?
Thanks your help.
- (void)drawRect:(CGRect)theRect{
CGRect rect = self.bounds;
//text label
UILabel * pText = [[UILabel alloc] initWithFrame: rect];
pText.text = @"demo";
// Circle
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:rect];
rect = CGRectInset(rect, 5, 5);
[path appendPath:[UIBezierPath bezierPathWithOvalInRect:rect]];
path.usesEvenOddFillRule = YES;
[self.color set];
[path fill];
}
You need to add your UILabel to your view.
//text label
UILabel * pText = [[UILabel alloc] initWithFrame: rect];
pText.text = @"demo";
[self addSubview:pText];
[pText release];
You need to call :
[super drawRect:rect];
in order to draw your uilabel before drawing the circle.
精彩评论