Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8754273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:35:12+00:00 2026-06-13T13:35:12+00:00

I am using AFNetwork in my application to get some data from my web

  • 0

I am using AFNetwork in my application to get some data from my web service.
In these data, there are some images with random sizes, I need to add some UIImageView.

My problem is to adjust the image in the correct scale of UIImageView, in asynchronous mode.

Any idea how to do this?

EDIT

I am using the normal method of the Afnetwoking´s projects:

 [self setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"img_my_nophoto"]];

The logic inside this method is :

- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest 
          placeholderImage:(UIImage *)placeholderImage 
                   success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
                   failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
{
    [self cancelImageRequestOperation];

UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest];
if (cachedImage) {
    self.image = cachedImage;
    self.af_imageRequestOperation = nil;

    if (success) {
        success(nil, nil, cachedImage);
    }
} else {
    self.image = placeholderImage;

    AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
    [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
            self.image = responseObject;
            self.af_imageRequestOperation = nil;
        }

        if (success) {
            success(operation.request, operation.response, responseObject);
        }

        [[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest];


    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
            self.af_imageRequestOperation = nil;
        }

        if (failure) {
            failure(operation.request, operation.response, error);
        }

    }];

    self.af_imageRequestOperation = requestOperation;

        [[[self class] af_sharedImageRequestOperationQueue] addOperation:self.af_imageRequestOperation];
    }
}

The full class code:
https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking/UIImageView%2BAFNetworking.m

SOLUTION

I solve my problem setting the UIImageView with

self.contentMode = UIViewContentModeScaleAspectFill;

self.clipsToBounds=YES;

basically this set the image with the proper scale, and cut all the edges..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:35:13+00:00Added an answer on June 13, 2026 at 1:35 pm

    Edit:

    If I understand your problem correctly, you just need to set imageView.contentMode = UIViewContentModeScaleAspectFit on the ImageView you get from the Afnetworking FW.

    Or you could check the actual size of the image with: imageView.image.size and set the imageView’s frame accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a class to download images from web. Issue is there is
Using Android TelephonyManager an application can obtain the state of data activity over the
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using the Redis info command, I am able to get all the stats of
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
Using Microsoft SQL Server 2005, is there any way to see when a table
Using RavenDB within an ASP.NET MVC (4) application, what is the correct pattern for
Using mercurial, I've run into an odd problem where a line from one committer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.