IOS - changing behavior of UIImageView setImage: (custom setter)

I want to perform additional tasks when a UIImageView image is specified. I am trying to define my own customization method, but no luck.

h:

@property (nonatomic, strong, setter = setImage:) UIImage *image;

t

- (void)setImage:(UIImage *)image {
    self.image = image;
    // additional tasks here
}

This obviously carries an endless cycle. How to do it?

+3
source share
2 answers

Instead

    self.image = image;

do

    [super setImage:image];

In addition, you do not need to specify the installer, as this is the default value.

+5
source

Obviously you are calling the setter with self.image = image;

use to avoid this. _image = image;

0
source

All Articles