VCのUICollectionViewDelegateFlowLayout
拡張でcellWidth
とsizeForItemAtIndexPath
を定義するためにこれを使用しました。
デバイスの動的な高さと幅に応じてcellWidth
と定義されています。
let cellWidth = UIScreen.mainScreen().bounds.width/7 - 1
動的セル幅と高さをそれに応じて返す関数です。 同じ大きさの幅と高さが必要でした.7行7列が必要な場合は7で割ったので、1行でセルの必要性に応じて変更できます。
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSString *, id> *)attributes context:(nullable NSStringDrawingContext *)context
パラメータを使用する:あなたはこのNSStringのメソッドを使用することができますラベル、テキストとフォントの幅を知る
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: cellWidth, height: cellWidth)
}
しかし、 'UICollectionViewLayout'ではなく' UICollectionViewLayout'をサブクラス化しました。 –