I want to display image on UIImageView
using URL and NSString
. I am unable to show image.
My code is:
UIImageView *view_Im
-
Just do it
NSString *imgURL = @"imagUrl";
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgURL]];
[YourImgView setImage:[UIImage imageWithData:data]];
Using GCD : If you don't want to hang your application then you can download your image in background.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *imgURL = @"imagUrl";
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgURL]];
//set your image on main thread.
dispatch_async(dispatch_get_main_queue(), ^{
[YourImgView setImage:[UIImage imageWithData:data]];
});
});
- 热议问题