drawRect中的UILabel不绘制

发布于 2024-10-13 06:58:38 字数 630 浏览 2 评论 0原文

快速问题,我在带有 UILabel 和圆的 UIView 中得到了这个 drawRect 方法。圆绘制正确,但 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];


}

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


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏夜暖风 2024-10-20 06:58:38

您需要将 UILabel 添加到您的视图中。

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

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];
围归者 2024-10-20 06:58:38

您需要调用 :

[super drawRect:rect];

以便在绘制圆圈之前绘制 uilabel。

You need to call :

[super drawRect:rect];

in order to draw your uilabel before drawing the circle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文