ios - 设置 ImageView 的位置

标签 ios swift image

我想改 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.xframe.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/

相关文章:

iphone - 单击按钮时停止dispatch_time_t

iOS 警报横幅/标签?

c# - 返回相对图像路径的 html 帮助程序未显示图像,但在 View 中硬编码相同路径时显示

HTML 图像映射替代方案

javascript - 更改 src 后获取图像的高度

ios - 如何从应用商店中的应用恢复应用标识符

android - Cordova 平台安装 : iOS broken

ios - Swift:从接口(interface)类型数组转换为对象数组崩溃

ios - 无法将自定义单元格与 UITableView 一起使用

ios - iPad 上的 ActionSheet 崩溃(相机按钮)