アイテムのフローリストを表示したい。項目画像の幅は画面の幅で、高さは画像が伸縮しないようにする必要があります。IOS設定セルの高さがURLの画像の高さの幅の比率に依存する
以下のアイテム画像は、アイテムの名前とそのアイテムを所有するユーザーのユーザー名です。
私はこれをほとんど行っています。唯一の問題は、collectionViewカードの高さが設定されていることです(非動的)。したがって、通常、画像はカードをオーバーフローさせるか、カードの高さをすべて満たさず、空白があります。
カードの高さを画像の高さに応じて変更する方法はありますか?ここで
は「CollViewCell」と呼ばれる私のitemCellViewである:ここでは
import UIKit
import AlamofireImage
class CollViewCell: UICollectionViewCell {
@IBOutlet weak var imgCell: UIImageView!
@IBOutlet weak var labelCell: UILabel!
@IBOutlet weak var labelUserNameCell: UILabel!
}
コレクション
...
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
self.viewModel.getItems(self.viewModel.getCurrentUser()) { items in
self.collectionView.reloadData()
}
}
...
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: CollViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CollViewCell
cell.labelCell.text = self.viewModel.tableDict[indexPath.row]![0]
let imageUrl = NSURL(string: self.viewModel.tableDict[indexPath.row]![1])
cell.imgCell.af_setImageWithURL(imageUrl!, placeholderImage: nil, filter: nil, imageTransition: .CrossDissolve(0.2))
cell.labelUserNameCell.text = self.viewModel.tableDict[indexPath.row]![2]
return cell
}
...
に関係しているのViewControllerコードストーリーボード上のビューモードが縦横に設定されているが記入され、セマンティックは左から右へ