【发布时间】: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