XcodeでiOS8.4以上向けのアプリをアップロードしようとしたらアセットファイルがおかしいエラー吐かれた話
続きを読む
カテゴリー: iOS
carthage update したら 2段階認証で怒られた時
Carthage を使ってみようとセットアップして、いざ
carthage update --platform iOS
を実行した時に
Must specify two-factor authentication OTP code.
に遭遇してしまった時の話
CHTCollectionViewWaterfallLayout でセルの横幅取得
Pinterest風のCollectionViewを利用できるようにする
CHTCollectionViewWaterfallLayout
で、セルの横幅を取りたかったのでメモ
UICollectionViewLayout を拡張して実装
import Foundation import CHTCollectionViewWaterfallLayout extension UICollectionViewLayout { func getCHTItemWidth() -> CGFloat{ guard let collectionViewRect = self.collectionView?.bounds else { return 0 } if self is CHTCollectionViewWaterfallLayout { let me = self as! CHTCollectionViewWaterfallLayout let columnWidth = collectionViewRect.width - (me.sectionInset.left + me.sectionInset.right) return ( columnWidth - CGFloat(me.columnCount - 1) * me.minimumColumnSpacing ) / me.columnCount } else { return collectionViewRect.width } } }
使用方法
横幅:セルの横幅 縦幅:セルの横幅+60 のセルを返したい時
extension ViewController : CHTCollectionViewDelegateWaterfallLayout { func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: UICollectionViewLayout!, sizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize { let w = collectionViewLayout.getCHTItemWidth() return CGSize(width: w, height: w + 60) } }
セルの横幅に合わせた柔軟なレイアウトが組めて楽しいです