没有为UIImageView调用drawRect

没有为UIImageView调用drawRect

本文介绍了没有为UIImageView调用drawRect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的IB中有一个UIImageView,我用一个方法创建了一个UIImageView的子类drawRect:

I have a UIImageView in my IB and I created a subclass of UIImageView with one method drawRect:

@implementation UIImageViewLine

- (void)drawRect:(CGRect)rect
{
    NSLog(@"CALLED");
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    CGContextSetLineWidth(context, 1.0f);
    CGContextMoveToPoint(context, 0, 0);
    CGContextAddLineToPoint(context, self.frame.size.width, self.frame.size.height);
    CGContextStrokePath(context);

}

@end

我有将UIImageView的类更改为此子类,但从不调用drawRect。知道为什么吗?

I have changed the class of the UIImageView to this subclass, however the drawRect is never called. Any idea why?

推荐答案

UIImageView 不会调用 drawRect 当子类化时。

The UIImageView doesn't call drawRect when subclassed.

来自:

你可以简单地替换 UIImageView 按正常的 UIView 并在 UIView drawRect 方法或子图层。

You can simply replace the UIImageView by a normal UIView and draw the image and your custom drawings in the UIView's drawRect method or in child layers.

这篇关于没有为UIImageView调用drawRect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:48