2011-01-21 7 views
1

簡単な質問を描画していない、私はUILabelとcircle.The円とUIViewでこのdrawRect方法が正しく描画されてしまったが、UILabelではありません。UILabelは

アイデア?

ありがとうございました。

- (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]; 


} 

答えて

1

UILabelをビューに追加する必要があります。

[super drawRect:rect]; 

円を描画する前に、あなたのuilabelを描くために:

//text label 
UILabel * pText = [[UILabel alloc] initWithFrame: rect]; 
pText.text = @"demo"; 
[self addSubview:pText]; 
[pText release]; 
+5

これは 'drawRect'ではなく、一度実行される場所で行います。 'drawRect'は複数回呼び出されるかもしれません。 – mvds

+0

ええ、私はmvdsに同意します。 – Gianz

+0

すばらしかったThxみんな! UIBezierPathに描画命令が含まれているため、ビューオブジェクトでありrectではないため、UILabelを追加する必要はありますか? – chriz

0

あなたが呼び出す必要があります。