2014-10-14 1 views

답변

1

DLImageLoader를 사용할 것을 권장합니다. 그것은 대단히 잘 유지되고, iOS에서 기본적으로 중요합니다.

요즘 DLImageLoader에는 완벽한 스위프트 버전이 있습니다.

https://github.com/AndreyLunevich/DLImageLoader-iOS/tree/master/DLImageLoader

그것은 당신이 웹 서비스를 말할 때, 여기에 예를 들어 페이스 북의 사용자 아바타를 얻을하는 방법

-(UICollectionViewCell *)collectionView:(UICollectionView *)cv 
     cellForItemAtIndexPath:(NSIndexPath *)indexPath 
    { 
    NSInteger thisRow = indexPath.row; 
    BooksCell *cell; 
    cell = [cv dequeueReusableCellWithReuseIdentifier: 
       @"CellBooksNormal" forIndexPath:indexPath]; 

    cell.layer.shouldRasterize = YES; 
    cell.layer.rasterizationScale = [UIScreen mainScreen].scale; 

    // set text items... 
    cell.title = @"blah"; 

    // set image items using DLImageLoader 

    __weak UIBookView *loadMe = cell.anImage; 
    [DLImageLoader loadImageFromURL:imUrl 
     completed:^(NSError *error, NSData *imgData) 
     { 
     [loadMe use:[UIImage imageWithData:imgData]]; 
     }]; 

    return cell; 
    } 

... 제대로 이미지를로드 할이 쉽게

PFObject *aFacebookUser = [self.fbFriends objectAtIndex:thisRow]; 
NSString *facebookImageURL = [NSString stringWithFormat: 
    @"http://graph.facebook.com/%@/picture?type=large", 
    [aFacebookUser objectForKey:@"id"] ]; 

__weak UIImageView *loadMe = self.cellImage; 
[DLImageLoader loadImageFromURL:facebookImageURL 
    completed:^(NSError *error, NSData *imgData) 
    { 
    if (loadMe == nil) return; 

    if (error == nil) 
     { 
     UIImage *image = [UIImage imageWithData:imgData]; 
     image = [image ourImageScaler]; 
     loadMe.image = image; 
     } 
    else 
     { 
     // an error when loading the image from the net 
     } 
    }]; 
+0

원래의 질문은 SDImageCache에 관한 것입니다. 왜 DLImageLoader가 그것의 활동 외에도 더 좋은가? API인가, 캐시 방법 등등? – TruMan1