繁体   English   中英

自定义UIView子类的drawRect不在UITableViewCell内部调用

[英]Custom UIView Subclass's drawRect not being called inside UITableViewCell

背景:我有UITableViewCell的子类,其布局被定义为情节提要中的原型单元。 单元格的IBOutletsUIView的子类,称为BorderedProfileImageView 此类的drawRect:函数被重写,如下所示:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
    CGContextSetLineWidth(context, 1.f);
    CGFloat halfWidth = self.bounds.size.width/2;
    NSInteger radius = sqrt(pow(halfWidth, 2) + pow(halfWidth, 2)) - 8.5;
    CGContextAddArc(context,self.bounds.size.width/2,self.bounds.size.height/2,radius,0,2*3.1415926535898,1);
    CGContextStrokePath(context);
}

这会向UIView添加一个蓝色的环。

问题:
蓝色的环永远不会出现,并且BorderdProfileImageViewdrawRect:函数永远不会被调用。 细胞仍然吸引,在UIImageView是内部BorderdProfileImageView被绘制。 设置单元格时,我确实在BorderedProfileImageView上调用setNeedsDisplay

为什么drawRect:没有被调用?

我想到了。

IB中设置为BorderedProfileImageView的对象最初是UIImageView 将此对象更改为UIView并重新链接已导致所需的行为。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM