问题描述:

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.

相关阅读:
Top