我想改 rebase 于不同设备的 ImageView 的位置。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier0, forIndexPath: indexPath) as! CelebrityHeaderCell
let CelebrityTopObj = self.mCelebrityTop[indexPath.item]
if CelebrityTopObj.video_pic != nil
{
SDWebImageManager.sharedManager().downloadImageWithURL(NSURL(string: CelebrityTopObj.video_pic), options: .LowPriority, progress: { (min:Int, max:Int) -> Void in
}) { (vimage:UIImage!, error:NSError!, cacheType:SDImageCacheType, finished:Bool, url:NSURL!) -> Void in
if vimage != nil && finished
{
if getScreenHeight()<=568 {
cell.VideoImg.image = imageResize(vimage, sizeChange: CGSize(width: self.screenWidth/2.5, height: self.screenWidth/3))
cell.PrevIcon.image = imageResize(UIImage(named: "icon_prev")!, sizeChange: CGSize(width: 25, height: 25))
cell.NextIcon.image = imageResize(UIImage(named: "icon_next")!, sizeChange: CGSize(width: 25, height: 25))
cell.TopName.font = cell.TopName.font.fontWithSize(15)
cell.PrevIcon.frame.origin.x = 10
cell.PrevIcon.frame.origin.y = 30
cell.PrevIcon.frame = CGRect(x: 10, y: 30, width: 25, height: 25)
} else {
cell.VideoImg.image = imageResize(vimage, sizeChange: CGSize(width: self.screenWidth/2, height: 100))
cell.PrevIcon.image = imageResize(UIImage(named: "icon_prev")!, sizeChange: CGSize(width: 55, height: 55))
cell.NextIcon.image = imageResize(UIImage(named: "icon_next")!, sizeChange: CGSize(width: 55, height: 55))
}
}
}
}
return cell
}
我想使用 frame.origin.x
和 frame.origin.y
设置 PrevIcon
的位置,但它没有工作。如何设置位置?
http://gfamily.cwgv.com.tw/public/images/iphone5.png
最佳答案
要设置新位置,请尝试类似的操作:
cell.PrevIcon.frame = CGRect(x: 10, y: 50, width: cell.PrevIcon.frame.bounds.width, height: cell.PrevIcon.frame.bounds.width)
要更改“框架”的参数,您必须使用 CGRect() 对其进行设置。您不能只编辑单个值。
关于ios - 设置 ImageView 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39484394/