zoukankan      html  css  js  c++  java
  • 解决UITableView中image加载不同宽度尺寸图片的问题

    如果你在寻找一个UITableView加载远程图片的方法,推荐一个第三方类库:SDWebImage。这个类库为你的工程提供了灵活的加载&缓存网络图片的方法,而且非常容易在工程中使用。

    但当我开始使用时,当我加载不同分辨率的网络图片时,发现图片出现了不同宽度,很不美观,为了解决这个问题,我们需要对webimage中的不同宽度进行限制。

    下面是一个简便有效的处理方法,自定义layoutSubviews:

    1 - (void)layoutSubviews {
    2     [super layoutSubviews];
    3     self.imageView.frame = CGRectMake(5,5,40,32.5);
    4     float limgW =  self.imageView.image.size.width;
    5     if(limgW > 0) {
    6         self.textLabel.frame = CGRectMake(55,self.textLabel.frame.origin.y,self.textLabel.frame.size.width,self.textLabel.frame.size.height);
    7         self.detailTextLabel.frame = CGRectMake(55,self.detailTextLabel.frame.origin.y,self.detailTextLabel.frame.size.width,self.detailTextLabel.frame.size.height);
    8     }
    9 }
     1 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     2 {
     3     static NSString *CellIdentifier = @"Cell";
     4     
     5     MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     6     if (cell == nil) {
     7         cell = [[MyCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
     8     }
     9     
    10     // Configure the cell...
    11     [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
    12                    placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    13     return cell;
    14 }
    作者:W.M.steve
    出处:http://www.cnblogs.com/weisteve/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    toj 1410. Euclid's Game 夜
    hdu 1404 Digital Deletions 夜
    hdu 1536 SNim 夜
    1180. Stone Game 夜
    hdu 1729 Stone Game 夜
    一个有价值的 Sharepoint WebPart 页签部件
    开始 MS Project & P3 E/C 探讨历程!
    cvccomplextype.3.2.2: Attribute 'singleton' is not allowed to appear in element 'bean
    启迪技术
    上传图片:
  • 原文地址:https://www.cnblogs.com/weisteve/p/3033195.html
Copyright © 2011-2022 走看看