【问题标题】:UILabel in drawRect does not drawdrawRect中的UILabel不绘制
【发布时间】:2011-01-21 02:45:09
【问题描述】:

快速提问,我在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];


}

【问题讨论】:

    标签: objective-c ios uiview uilabel


    【解决方案1】:

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

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

    【讨论】:

    • 这个,但是不要在drawRect做这个,而是在一个做一次的地方。 drawRect 可能会被多次调用。
    • 谢谢你们这么快!我是否需要添加 UILabel 因为它是一个视图对象而不是 rect 因为 UIBezierPath 包含绘制指令?
    【解决方案2】:

    你需要打电话:

    [super drawRect:rect];
    

    为了在画圆之前画出你的uilabel。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2012-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多