More Related Content
More from Kosuke Usami (20)
Auto Layout Tips
- 2. Auto Layout
→ iOS / OS X でのビューのレイアウト手法
→ 制約を定義することでサイズや位置を自動計算
→ 従来のフレームベースレイアウトと発想が異なる
- 4. UIKit デザインパターンと Auto Layout
→ UIScrollView と Auto Layout
→ UITableView と Auto Layout
→ UICollectionView と Auto Layout
→ これらの組み合わせは案外たいへん
- 7. Content View
→ まず UIScrollView の内側に Content View を作る
→ UIScrollView と Content View との上下左右の各辺
に制約を定義する
→ これで contentSize = Content View のサイズとな
る
- 8. うまくいくパターン
→ Content View のサイズを UIScrollView の 外側 に
ある要素から決まるようにする
→ 例えば次のような階層のとき
→ (1) UIView - (2) UIScrollView - (3) Content View
→ (3) のサイズが (1) から決まるようにする
→ (例えば、幅が等しいとか)
- 13. Self Sizing Cell (iOS 8)
→ tableView:estimatedHeightForRowAtIndexPath: で
仮の高さを返す
→ tableView:heightForRowAtIndexPath: で
UITableViewAutomaticDimension を返す
→ これで Auto Layout で決まる高さが Cell の高さに
- 15. 注意 : Storyboard 上の設定
→ Storyboard 上では UITableViewCell の高さ入力要
→ Cell の高さと Content View の高さを整合させる
→ Content View のレイアウトを組みながら、それに
あわせて Cell の高さを調整・・・(正直だるい)
- 19. Self Sizing Cell (iOS 8)
→ estimatedItemSize に仮のサイズを返す
(UISizeZero 以外)
→ itemSize は設定しなくて良い
→ これで Auto Layout のサイズが Cell サイズに