Last active
December 10, 2015 00:29
-
-
Save lbj96347/4351880 to your computer and use it in GitHub Desktop.
Objective-C Cocoa Load Online Image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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