`
836811384
  • 浏览: 548499 次
文章分类
社区版块
存档分类
最新评论

EGOImageView与SDWebImage

阅读更多
http://blog.csdn.net/kbawyg/article/details/8092946

EGOImageView是一种实现网络图片的异步加载和缓存的第三方类库,具有相同功能的第三方类库还有SDWebImage。但是相比两个类库的安装和使用来说,EGOImageView更简单一些,下面就介绍一下EGOImageView的使用方法:

<wbr><wbr>1、下载EGOImageView及其相关的类库</wbr></wbr>

<wbr><wbr><wbr><a href="https://github.com/enormego/EGOImageLoading" target="_blank" style="text-decoration:none; color:rgb(62,115,160)">EGOImageLoading</a></wbr></wbr></wbr>

<wbr><wbr>将EGOCache、EGOImageButton、EGOImageView、EGOImageLoader全部添加到工程下(拷贝)</wbr></wbr>

<wbr><wbr>2、EGOImagView使用代码如下 <wbr><wbr></wbr></wbr></wbr></wbr>


  1. EGOImageView<wbr>*imageView<wbr>=<wbr>[[EGOImageView<wbr>alloc]<wbr>initWithPlaceholderImage<wbr>:[UIImage<wbr>imageNamed:@"placeholder.png"]];<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  2. imageView.imageURL<wbr>=<wbr>[NSURL<wbr>URLWithString:@"http://....../images/1.jpg"];<wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  3. imageView.frame<wbr>=<wbr>CGRectMake(x,x,x,x);<wbr><wbr></wbr></wbr></wbr></wbr>
  4. [self.view<wbr>addSubView:imageView];<wbr><wbr></wbr></wbr></wbr>
<wbr style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)"><span style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)"></span><wbr style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)"><span style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)">placeholder.png</span><span style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)">是加载图片未完成时显示的图片,当加载过程完成之后</span><span style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)">就会显示url对应的图片。 </span><wbr style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)"><span style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)"></span><wbr style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)"><span style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)"></span><wbr style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)"><span style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)"></span> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(70,70,70); font-family:simsun; font-size:14px; text-align:left; background-color:rgb(188,211,229)"> <br><wbr><wbr>3、需要特别注意的是EGOImageView的一个非常奇葩的Bug</wbr></wbr></p> <p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px; list-style:none; word-wrap:normal; word-break:normal; line-height:21px; color:rgb(70,70,70); font-family:simsun; font-size:14px; text-align:left; background-color:rgb(188,211,229)"> <wbr><wbr>当imageView的图片加载完成了,这时你想换一个图片的url并用EGOImageView加载这个图片时,需要重新设置EGOImageView 的imageURL属性。但是这里要特别注意的是这个方法必须在主线程中执行,找到这个Bug我费了很大的劲,在用英文的Google搜索了好几页才找到 一位同是天涯沦落人的Coder,于是有了下面的代码</wbr></wbr></p> <div style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; text-align:left; background-color:rgb(188,211,229)"> <div><br></div> <ol start="1" style="margin:0px; padding:0px; border:0px; list-style:none"><li style="margin:0px 0px 0px 30px; padding:0px; border:0px; list-style:decimal"> <span style="word-wrap:normal; word-break:normal">[imageView<wbr>performSelectorOnMainThr<wbr>ead:@selector(setImageURL:)<wbr>withObject:[NSURL<wbr>URLWithString:@"http://....../images/2.jpg"]<wbr>waitUntilDone:NO];</wbr></wbr></wbr></wbr></wbr></span> </li></ol> </div> </wbr></wbr></wbr></wbr></wbr>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics