【问题标题】:UITableViewCell Custom Image Size, Shadow And BordersUITableViewCell 自定义图片大小、阴影和边框
【发布时间】:2013-10-17 15:33:59
【问题描述】:

以下是我从 App Store 的应用中截取的图片:

我创建了一个使用 StoryBoard 和自定义 tableview 单元格的应用程序。数据是从 Web 服务加载到其中的。这就是我想要的:

1) 如何根据图片改变uitableviewcell的大小?例如,如果一张图片是 640*500,那么 UITableViewCell 会相应地改变它的大小。如果图片的大小是640*1000,那么单元格应该相应地改变它的大小。

2)我怎样才能像上图一样在表格视图单元格周围添加灰色边框?

3)我怎样才能像上图一样添加从 UITableViewCell 中落下的阴影?

谢谢!

【问题讨论】:

    标签: iphone ios uitableview uiimageview


    【解决方案1】:

    目前我对您的问题有部分答案。问题的第二部分是彩色边框可以通过以下代码解决:

    [cell.contentView.layer setBorderColor:[UIColor colorWithRed:222/255.0f green:222/255.0f blue:222/255.0f alpha:1.0f].CGColor];
    [cell.contentView.layer setBorderWidth:5.0f];
    

    【讨论】:

      【解决方案2】:

      第 1 部分 tableviewcell 的高度是使用确定的

      - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
      {
         /*
          Get the image size 
          CGFloat width = myImage.size.width;
          CGFloat height = myImage.size.height;
          use this to return the height of your cell. 
         */
      }
      

      第 2 部分和第 3 部分 使用..

      - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
      
         //This will give you access to the cell being rendered and any customization you want can be done here... You can use the earlier answer for this part.. I havent tried it but should work..
      }
      

      希望这会有所帮助..

      【讨论】:

      • 我需要先更改 UIImageView 的大小,然后再更改单元格的高度吗?
      • 返回高度考虑UIImageView的大小,然后可以在cellForRowAtIndexPath里面手动设置UIImageView的frame
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多