Skip to content

Instantly share code, notes, and snippets.

@lbj96347
Last active December 10, 2015 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbj96347/4351880 to your computer and use it in GitHub Desktop.
Save lbj96347/4351880 to your computer and use it in GitHub Desktop.
Objective-C Cocoa Load Online Image
- (BOOL) loadWebImage
{
BOOL result = NO;
UIImage* image=nil;
NSString* path =[NSString stringWithFormat: @"http://www.cashlee.me/images/cashlee.jpeg",[self.title UTF8String]];
NSURL* url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];//网络图片url
NSData* data = [NSData dataWithContentsOfURL:url];//获取网咯图片数据
if(data!=nil){
StampUtility* theUtil = [[[StampUtility alloc] init] autorelease];//使用autorelease 实现自动释放资源,主要用于临时变量
image = [[UIImage alloc] initWithData:data];//根据图片数据流构造image
[image release];
result = YES;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment