Claire
Claire

Reputation: 37

Set the position of Image View

I want to change the position of image view that is based on different devices.

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 
}

I want to set the position of PrevIcon by using frame.origin.x and frame.origin.y but it doesn't work. How do I do to set the position? http://gfamily.cwgv.com.tw/public/images/iphone5.png

Upvotes: 0

Views: 1278

Answers (2)

Carien van Zyl
Carien van Zyl

Reputation: 2873

Also have a look at size classes in storyboard. Size classes enables you to have different layout constraints for different device types and orientations. Here is a link to a quick tutorial.

Upvotes: 0

Kevin Lieser
Kevin Lieser

Reputation: 977

To set the new position try something like that:

cell.PrevIcon.frame = CGRect(x: 10, y: 50, width: cell.PrevIcon.frame.bounds.width, height: cell.PrevIcon.frame.bounds.width)

To change a parameter of the "frame" you have to set it with CGRect(). You cant edit just a single value.

Upvotes: 1

Related Questions