異なるデバイスに基づくイメージビューの位置を変更したい。イメージビューの位置を設定する
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
の位置を設定したいが、それは動作しません。ポジションを設定するにはどうすればいいですか?あなたはCGRect(とそれを設定する必要があり、「フレーム」)のパラメータを変更するには
cell.PrevIcon.frame = CGRect(x: 10, y: 50, width: cell.PrevIcon.frame.bounds.width, height: cell.PrevIcon.frame.bounds.width)
:新しい位置を設定するには http://gfamily.cwgv.com.tw/public/images/iphone5.png
このメソッドを試しましたが、動作しませんでした.http://gfamily.cwgv.com.tw/public/images/iphone5.png私のコードは "cell.PrevIcon.frame = CGRect(x:10、 y:10、width:25、height:25) " –
正規の構文正しいコードです。それはうまくいくはずです - それが問題でなければ他の場所にあります。コードが実行され、 'getScreenHeight()<= 568 {...}'であれば本当ですか? スクリーンショットはあなたの問題を理解するのに役立つものではありません。しかし、なぜ画像のサイズを変更していますか?ちょうど 'cell.PrevIcon.contentMode = UIViewContentMode.scaleAspectFit'を使用してください –