【问题标题】:Convert UITableViewCell into UIImageView [duplicate]将 UITableViewCell 转换为 UIImageView [重复]
【发布时间】:2013-07-07 15:19:26
【问题描述】:

有没有办法可以将 UITableViewCell 或 UICollectionViewCell 的视图转换为看起来相同的 UIImageView?

我希望能够将单元格的快照转换为 UIImageView,以便能够为 UIImageView 设置动画。单元格本身可以保持不变。

【问题讨论】:

  • Google for UIImage from UIView,这会让你开始

标签: ios objective-c uitableview uiimageview


【解决方案1】:

您可以使用以下代码:

UIGraphicsBeginImageContextWithOptions(cell.bounds.size, cell.opaque, 0.0);
[cell.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *cellImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

【讨论】:

    【解决方案2】:

    在视网膜设备上你应该使用这个

    CGFloat scale = [[UIScreen mainScreen] scale];
    UIGraphicsBeginImageContextWithOptions(frame.size, YES, scale);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    如果单元格有透明部分,UIGraphicsBeginImageContextWithOptions 中的第二个参数应该是NO

    【讨论】:

      猜你喜欢
      • 2012-07-15
      • 2012-01-19
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多