当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - 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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: