Mark Lorenz
Mark Lorenz

Reputation:

UIImageView subclass does not display

I am using a custom subclass of UIImageView, but I can't figure out why it's not being displayed.

The relevant code from my UIImageView subclass:
-(id) initWithImage:(UIImage*)image{
    if(self = [super initWithImage:image]){

    }
    return self;
}

And from the view controller for the view that will be displaying my subclass:

UIImage *zoomRatateSliderHorizontal = 
       [[UIImage imageNamed:@"ZoomRotate Slider Horizontal.png"]
      stretchableImageWithLeftCapWidth:(75.0)/2-1.0  topCapHeight:0]; 
scaleHorizontalControl = [[ViewTransformationController alloc] 
                     initWithImage:zoomRatateSliderHorizontal];
scaleHorizontalControl.onScreenFrame = CGRectMake(0.0, 5.0,  
                                   self.view.frame.size.width, 
                                   scaleHorizontalControl.image.size.height);
scaleHorizontalControl.frame = scaleHorizontalControl.onScreenFrame;
scaleHorizontalControl.offScreenFrame = CGRectZero;
[self.view addSubview:scaleHorizontalControl];

Before I was subclassing, I had no trouble with the following in the view controller:

UIImage *zoomRatateSliderVertical = 
                    [[UIImage imageNamed:@"ZoomRotate Slider Vertical.png"]
                    stretchableImageWithLeftCapWidth:0  topCapHeight:(75.0)/2-1.0]; 
scaleOrRatateViewVertical = [[UIImageView alloc] 
                             initWithImage:zoomRatateSliderVertical];
scaleOrRatateViewVertical.frame = CGRectMake(-zoomRatateSliderVertical.size.width,
                                  zoomRatateSliderHorizontal.size.height+5.0+5.0, 
                                  zoomRatateSliderVertical.size.width, 
                           465.0 - zoomRatateSliderHorizontal.size.height-10.0-5.0);
[self.view addSubview:scaleOrRatateViewVertical];

Using break points I checked the frame and image being passe to my class, and they both appear to be valid and desired.

Any advice on what I'm doing wrong I'd greatly appreciate.

Upvotes: 0

Views: 3237

Answers (1)

mjhoy
mjhoy

Reputation: 461

The Apple Docs read:

The UIImageView class is optimized to draw its images to the display. UIImageView will not call drawRect: a subclass. If your subclass needs custom drawing code, it is recommended you use UIView as the base class.

So I'd subclass UIView and work from there.

Upvotes: 4

Related Questions