【问题标题】:How do I adjust the position of an imageview in a uicollectionview cell?如何调整 uicollectionview 单元格中 imageview 的位置?
【发布时间】:2016-07-11 23:58:05
【问题描述】:

我在 UICollectionView 单元格中有一个 UIImageView,我正在根据屏幕大小以编程方式调整其大小。这些单元格创建了两列,我希望在查看集合时图像显示在更靠近屏幕中心的位置。

override func collectionView(collectionView: UICollectionView,    cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ProfileCollectionViewCell

    cell.myLabel?.text = fetchName()
    cell.myImage?.image = fetchImage()

    if(indexPath.item % 2 == 0) {
        cell.myImage?.frame.origin.x = (cell.frame.size.width / 3) * 2
        cell.myImage?.frame.origin.y = cell.frame.size.height / 2
    }
    else {
        cell.myImage?.frame.origin.x = (cell.frame.size.width / 3)
        cell.myImage?.frame.origin.y = cell.frame.size.height / 2
    }

    cell.myImage?.layer.cornerRadius = (cell.myImage?.frame.size.width)! / 2
    cell.myImage?.layer.masksToBounds = true
    return cell
}

这似乎并没有真正移动图像视图。我也尝试调整 cell.myImage?.center 但这也没有任何效果。那么如何在这个单元格周围移动我的图像呢?

【问题讨论】:

  • 可以分享截图吗

标签: ios swift uiimageview uicollectionview uicollectionviewcell


【解决方案1】:

尝试在您的ProfileCollectionViewCell layoutSubviews 方法中为您调整位置imageView 这是您想要实现的目标的地方

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-24
    • 2016-10-28
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    相关资源
    最近更新 更多