[英]Custom UIView Subclass's drawRect not being called inside UITableViewCell
背景:我有UITableViewCell
的子类,其布局被定义为情节提要中的原型单元。 单元格的IBOutlets
是UIView
的子类,称为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添加一个蓝色的环。
问题:
蓝色的环永远不会出现,并且BorderdProfileImageView
的drawRect:
函数永远不会被调用。 细胞仍然吸引,在UIImageView
是内部BorderdProfileImageView
被绘制。 设置单元格时,我确实在BorderedProfileImageView
上调用setNeedsDisplay
。
为什么drawRect:
没有被调用?
我想到了。
IB中设置为BorderedProfileImageView
的对象最初是UIImageView
。 将此对象更改为UIView
并重新链接已导致所需的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.