imageasynchronousloadingios-4.2

setContentMode: for HJManagedImageV is not working for iOS


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.


Solution

  • 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.