{"id":429,"date":"2016-10-31T07:18:45","date_gmt":"2016-10-30T22:18:45","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=429"},"modified":"2018-01-01T12:00:42","modified_gmt":"2018-01-01T03:00:42","slug":"swift-collectionview%e3%81%ae%e3%82%bb%e3%83%ab%e3%81%ae%e9%96%93%e9%9a%94%e3%82%92%e5%a4%89%e6%9b%b4","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/swift-collectionview%e3%81%ae%e3%82%bb%e3%83%ab%e3%81%ae%e9%96%93%e9%9a%94%e3%82%92%e5%a4%89%e6%9b%b4\/","title":{"rendered":"[swift] CollectionView\u306e\u30bb\u30eb\u306e\u9593\u9694\u3084\u30bb\u30eb\u306e\u30b5\u30a4\u30ba\u3092\u5909\u66f4 (cell margin)"},"content":{"rendered":"<h2>CollectionView\u306e\u30bb\u30eb\u306e\u9593\u9694\u3092\u5909\u66f4<\/h2>\n<p>CollectionView\u306e\u30bb\u30eb\u306e\u9593\u9694\u3092\u5909\u66f4\u3059\u308b\u306b\u306f\u300cinsetForSectionAtIndex\u300d\u3067UIEdgeInsets\u3092return\u3059\u308c\u3070\u826f\u3044<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\uff1a<\/p>\n<pre class=\"\">func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -&gt; UIEdgeInsets {\r\n        return UIEdgeInsetsMake(5, 10, 0, 7)\r\n    }\r\n<\/pre>\n<p>\u4e0a\u8a18\u8a2d\u5b9a\u3067\u5404\u30bb\u30eb\u306e\u4e0a5px\u3001\u5de610px\u3001\u4e0b0px\u3001\u53f37px\u306e\u4f59\u767d\u3092\u958b\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b<\/p>\n<p>&nbsp;<\/p>\n<p>Swift4\u3067\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3001CollectionView\u306e\u30bb\u30eb\u306e\u9593\u9694\u3084\u30b5\u30a4\u30ba\u3092\u5909\u66f4\u3067\u304d\u308b<\/p>\n<pre class=\"lang:default decode:true \">let margin: CGFloat = 20.0\r\n\r\n\r\nextension ViewController: UICollectionViewDelegateFlowLayout {\r\n \r\n func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {\r\n  \/\/ \u4f8b\u3048\u3070\u7aef\u672b\u30b5\u30a4\u30ba\u3092 3 \u5217\u306b\u3059\u308b\u5834\u5408\r\n  let width: CGFloat = UIScreen.main.bounds.width \/ 3 - margin*2\r\n  let height = width\r\n  return CGSize(width: width, height: height)\r\n }\r\n \r\n func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -&gt; UIEdgeInsets {\r\n  return UIEdgeInsets(top: margin, left: margin, bottom: margin, right: margin)\r\n }\r\n \r\n func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -&gt; CGFloat {\r\n  return margin\r\n }\r\n \r\n func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -&gt; CGFloat {\r\n  return margin\r\n }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>CollectionView\u306e\u30bb\u30eb\u306e\u9593\u9694<\/p>\n","protected":false},"author":1,"featured_media":88,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/429"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=429"}],"version-history":[{"count":9,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/429\/revisions"}],"predecessor-version":[{"id":1488,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/429\/revisions\/1488"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/88"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}