If you want to maintain the aspect ratio of an image, use
contentMode=UIViewContentModeScaleAspectFit
contentMode=UIViewContentModeScaleAspectFill (if you want to use full layout) and masking with width or height, Make sure that use Bitwise operator used i.e UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleHeight
* masking is working only upon if content mode is set.
* setImageWithURLRequest, use this function:
#import "UIImageView+AFNetworking.h"
contentMode=UIViewContentModeScaleAspectFill (if you want to use full layout) and masking with width or height, Make sure that use Bitwise operator used i.e UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleHeight
* masking is working only upon if content mode is set.
* setImageWithURLRequest, use this function:
#import "UIImageView+AFNetworking.h"
UIImageView *imgView = [[UIImageView alloc] init]; imgView.contentMode = UIViewContentModeScaleAspectFit; imgView.clipsToBound = YES; imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; UIActivityIndicatorView *loadingIndicator =[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; loadingIndicator.center=CGPointMake(150,75); NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"YOUR_URL"]]; [imgView addSubview:loadingIndicator]; [self.view addSubview:imgView]; [loadingIndicator setHidden:NO]; [loadingIndicator startAnimating]; [imgView setImageWithURLRequest :imageRequest placeholderImage:nil success:^(NSURLRequest *request,NSHTTPURLResponse *response,UIImage *image){ [loadingIndicator setHidden:YES]; [loadingIndicator stopAnimating]; imgView.image = image; //Here you set your frame accordingly CGSize size = img.size; imgView.frame = CGRectMake(xOffset,yOffset,size.width,size.height); }failure:^(NSURLRequest *request,NSHTTPURLResponse *response, NSError *error){ [loadingIndicator setHidden:YES]; [loadingIndicator stopAnimating]; }];
No comments:
Post a Comment