Showing posts with label UIIMage. Show all posts
Showing posts with label UIIMage. Show all posts

Thursday, 10 October 2013

Image URL load via AFNetworking | Wait Indicator placed while loading URL on UIImageView | Exact width/height of image width/height

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"
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];
}];

Thursday, 26 April 2012

Navigation - bar set background image for both ios5 & ios 4

In ios > 5 API updated with barMetrics arguments to setbackgroundimage for UInavigationbar and in ios < 5 only & only option to set background-image on navigationbar by calling drawRect () function  but it didn't work for me , resulting some errors on this.After being a lot of search on this but i'm totally failed.So,I did some trick on this and it works for me.

if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
For ios 5 or above

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"YOUR_IMAGE_NAME_WITH_EXTENSION"] forBarMetrics:UIBarMetricsDefault];
}
else {

 For ios 4 or less 

NSString *barBgPath = [[NSBundle mainBundle] pathForResource:@"YOUR_IMAGE_NAME" ofType:@"YOUR_IMAGE_EXTENSION"];

[self.navigationController.navigationBar.layer setContents:(id)[UIImage imageWithContentsOfFile: barBgPath].CGImage];

self.navigationController.navigationBar.alpha=1.0; //If you want change alpha

}

Cheers:)
Enjoyyyyyy!