iPhone開發筆記(20)EGOImageView的使用方法及注意事項

來源:互聯網
上載者:User

    EGOImageView是一種實現網狀圖片的非同步載入和緩衝的第三方類庫,具有相同功能的第三方類庫還有SDWebImage。但是相比兩個類庫的安裝和使用來說,EGOImageView更簡單一些,下面就介紹一下EGOImageView的使用方法:

    1、下載EGOImageView及其相關的類庫

    EGOImageLoading

    將EGOCache、EGOImageButton、EGOImageView、EGOImageLoader全部添加到工程下(拷貝)

    2、EGOImagView使用代碼如下    

EGOImageView *imageView = [[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:@"placeholder.png"]];imageView.imageURL = [NSURL URLWithString:@"http://....../images/1.jpg"];imageView.frame = CGRectMake(x,x,x,x);[self.view addSubView:imageView];

    placeholder.png是載入圖片未完成時顯示的圖片,當載入過程完成之後就會顯示url對應的圖片。     

    3、需要特別注意的是EGOImageView的一個非常奇葩的Bug

    當imageView的圖片載入完成了,這時你想換一個圖片的url並用EGOImageView載入這個圖片時,需要重新設定EGOImageView的imageURL屬性。但是這裡要特別注意的是這個方法必須在主線程中執行,找到這個Bug我費了很大的勁,在用英文的Google搜尋了好幾頁才找到一位同是天涯淪落人的Coder,於是有了下面的代碼

[imageView performSelectorOnMainThread:@selector(setImageURL:) withObject:[NSURL URLWithString:@"http://....../images/2.jpg"] waitUntilDone:NO];

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.