AlbumArt.m
- (id)initWithFrame:(CGRect)frame aaurl:(NSString *)cont
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
if([cont isEqual:[NSNull null]]){
self.image=[UIImage imageNamed:@"ina"];
return self;
}
if(!ai) ai=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[ai setCenter:self.center];[self addSubview:ai];[ai startAnimating];
data=[[NSMutableData alloc]initWithCapacity:0];
NSURLRequest *req=[NSURLRequest
requestWithURL:[NSURL URLWithString:cont]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
conne=[[NSURLConnection alloc]initWithRequest:req delegate:self];
}
return self;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
if([((NSHTTPURLResponse *)response) statusCode]!=200){
data=[[NSMutableData alloc]initWithData:UIImagePNGRepresentation([UIImage imageNamed:@"ina"])];
self.image=[UIImage imageWithData:data];
[self abort];
}
else [data setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)rdata{
[data appendData:rdata];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
[self abort];
NSLog(@"error.");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
[ai removeFromSuperview];
UIImage *aa=[UIImage imageWithData:data];
UIImageView *aav=[[UIImageView alloc]initWithImage:aa];
UIImage *border=[UIImage imageNamed:@"gray"];
UIImageView *borderv=[[UIImageView alloc]initWithImage:border];
[aav setFrame:CGRectMake(3,3,204,204)];
[borderv setFrame:CGRectMake(0,0,210,210)];
[self addSubview:borderv];[self addSubview:aav];
[self setFrame:CGRectMake((self.frame.size.width-210)/2,(self.frame.size.height-210)/2,210,210)];
}
-(void)abort{
if(conne!=nil){[conne cancel];conne=nil;}
if(data!=nil) data=nil;
}
できた。
0 件のコメント:
コメントを投稿