Question

I am using a third party lib, HJCacheClasses, for loading images asynchronously. Here is the code for the same. It's pretty much straightforward:

NSMutableString *url = @"my url";
    HJManagedImageV *asyncImageView = [[HJManagedImageV alloc] initWithFrame:frame];
    [asyncImageView setBackgroundColor:[UIColor grayColor]];
    [asyncImageView showLoadingWheel];
    [asyncImageView setContentMode:UIViewContentModeScaleAspectFill];
    [asyncImageView.imageView setContentMode:UIViewContentModeScaleAspectFill];
    asyncImageView.url = [NSURL URLWithString:url];

    [self.imageManager manage:asyncImageView];
    [the_pScrollView addSubview:asyncImageView];

Everything works fine except that the image is centered and it not getting stretched/fitted according to the size of the view (which is of size of full screen). I know the image is small but I need to make it fit in the view to fill the view. but none of the setContentMode are working.

Was it helpful?

Solution 2

I found the answer myself which I feel is more simpler and strightforward. As Ican mentioned,in the source code of the HJManagedImageV class,the author hardcoded the imageView of the HJManagedImageV instance to always be aspect fit. So I just commented that code... For people who like to do the same follow the following steps

  1. Go to HJManagedImageV.m file
  2. search for a method named

    -(void) setImage:(UIImage*)theImage
    
  3. comment the line

    imageView.contentMode = ...
    

    or set the content mode you want to for the imageView. Note: This will set the content mode for all the imageViews using this class. So I prefer to go with first option.

  4. In the code where you are using this class, set the content mode for the HJManagedImageV.

OTHER TIPS

If you have a look at the source code of the HJManagedImageV class, you will notice the author hardcoded the imageView of the HJManagedImageV instance to always be aspect fit. So by default you will never get aspect fill content mode working.

There's an easy way to achieve this though, right after you set the url property of the managed image view, add also a callback to your own class, like so:

myImageView.callbackOnSetImage = (id)self;

And in the callback function set the desired contentMode for the imageView, just like this. This is tested and works for me. Good luck

-(void) managedImageSet:(HJManagedImageV*)mi
{
    mi.imageView.contentMode = UIViewContentModeScaleAspectFill;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top