class MyCollectionViewController: UICollectionViewController { init() { let layout = UICollectionViewFlowLayout() let width = UIScreen.main.bounds.size.width / 2 layout.itemSize = CGSize(width: width, height: width) layout.minimumInteritemSpacing = 0 layout.minimumLineSpacing = 0 // navigation bar の分だけ下に下げる // widthはなんでもいい layout.headerReferenceSize = CGSize(width: 100, height: 68) // 親クラスのイニシャライザに渡してやる super.init(collectionViewLayout: layout) llet navigationBar = UINavigationBar( frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 44) ) let navigationBarTitle = UINavigationItem(title: "背景選択") navigationBar.setItems([navigationBarTitle], animated: false) self.view.addSubview(navigationBar) }
NavigationBarの分だけ