{"id":1262,"date":"2020-09-15T11:45:20","date_gmt":"2020-09-15T02:45:20","guid":{"rendered":"https:\/\/naoya-ono.com\/swift\/?p=1262"},"modified":"2020-09-15T12:36:00","modified_gmt":"2020-09-15T03:36:00","slug":"swift-collection-view-basic","status":"publish","type":"post","link":"https:\/\/naoya-ono.com\/swift\/swift-collection-view-basic\/","title":{"rendered":"\u3010Swift\u3011CollectionView\u306e\u4f7f\u3044\u65b9"},"content":{"rendered":"<p><span>\u3053\u306e\u30da\u30fc\u30b8\u3067\u306f\u3001UICollectionView\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b\u307e\u3067\u306e\u57fa\u672c\u7684\u306a\u6d41\u308c\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/span><\/p>\n<p>UITableView\u3068\u5c11\u3057\u4f3c\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u3061\u3089\u306e\u4f7f\u3044\u65b9\u304c\u7406\u89e3\u3067\u304d\u3066\u3044\u308c\u3070\u3001UICollectionView\u3082\u7406\u89e3\u3057\u3084\u3059\u3044\u3067\u3059\u3002<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#CollectionView\">CollectionView\u306e\u8a2d\u5b9a\u3092\u3059\u308b<\/a><ul><li><a href=\"#1_Collection_View\">1. Collection View\u306e\u8a2d\u7f6e<\/a><\/li><li><a href=\"#2_Outlets\">2. Outlets\u306e\u8a2d\u5b9a<\/a><\/li><\/ul><\/li><li><a href=\"#CollectionViewCell\">CollectionViewCell\u306e\u8a2d\u5b9a\u3092\u3059\u308b<\/a><ul><li><a href=\"#1_ID\">1. ID\u306e\u8a2d\u5b9a<\/a><\/li><li><a href=\"#2_UILabel\">2. \u30bb\u30eb\u306bUILabel\u3092\u30bb\u30c3\u30c8\u3059\u308b<\/a><\/li><li><a href=\"#3_tag\">3. tag\u306e\u8a2d\u5b9a<\/a><\/li><li><a href=\"#4_Estimate_Size\">4. Estimate Size\u306e\u8a2d\u5b9a<\/a><\/li><li><a href=\"#5\">5. \u30bb\u30eb\u540c\u58eb\u306e\u4f59\u8a08\u306a\u30b9\u30da\u30fc\u30b9\u3092\uff10\u306b\u3057\u3066\u304a\u304f<\/a><\/li><\/ul><\/li><li><a href=\"#ViewController\">ViewController\u3078\u306e\u8a18\u8ff0<\/a><ul><li><a href=\"#1\">1. \u30bb\u30eb\u306b\u8868\u793a\u3059\u308b\u30c7\u30fc\u30bf\u3092\u6e96\u5099<\/a><\/li><li><a href=\"#2_collectionView\">2. collectionView\u306e\u8868\u793a\u306b\u95a2\u9023\u3059\u308b\u51e6\u7406<\/a><\/li><li><a href=\"#3\">3. \u30bb\u30eb\u306e\u30b5\u30a4\u30ba\u3092\u8abf\u6574\u3059\u308b<\/a><\/li><\/ul><\/li><li><a href=\"#i\">\u884c\u9593\u3092\u6307\u5b9a\u3057\u305f\u3044\u5834\u5408<\/a><\/li><li><a href=\"#i-2\">\u30bb\u30eb\u306b\u4f59\u767d\u3092\u6301\u305f\u305b\u305f\u3044\u5834\u5408<\/a><\/li><li><a href=\"#i-3\">\u30bb\u30af\u30b7\u30e7\u30f3\u3054\u3068\u306b\u30d8\u30c3\u30c0\u30fc\u3092\u4ed8\u3051\u305f\u3044\u5834\u5408<\/a><\/li><\/ul><\/div>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-0\"><span id=\"CollectionView\"><span id=\"TableView\">CollectionView\u306e\u8a2d\u5b9a\u3092\u3059\u308b<\/span><\/span><\/h2>\n<p>\u307e\u305a\u306fStoryboard\u4e0a\u306bCollectionView\u3092\u8a2d\u7f6e\u3057\u3066\u3001\u8272\u3005\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<h3 id=\"i-1\"><span id=\"1_Collection_View\"><span id=\"1_Table_View\">1. Collection View\u306e\u8a2d\u7f6e<\/span><\/span><\/h3>\n<p><span>Objects\u4e00\u89a7\u304b\u3089\u300cCollection View\u300d\u3092\u691c\u7d22\u3057\u3066\u3001\u305d\u308c\u3092ViewController\u306b\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u3057\u307e\u3059\u3002<\/span><\/p>\n<p><span><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_42_22-1024x782.jpg\" alt=\"\" width=\"880\" height=\"672\" class=\"wp-image-1268 size-large aligncenter\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_42_22-1024x782.jpg 1024w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_42_22-300x229.jpg 300w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_42_22-768x587.jpg 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_42_22-1536x1173.jpg 1536w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_42_22-940x718.jpg 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_42_22.jpg 1998w\" sizes=\"(max-width: 880px) 100vw, 880px\"><\/span><\/p>\n<h3 id=\"i-2\"><span id=\"2_Outlets\"><span id=\"2_Outlets\">2. Outlets\u306e\u8a2d\u5b9a<\/span><\/span><\/h3>\n<p>\u7d9a\u3044\u3066\u3001CollectionView\u306eOutlets\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30bb\u30eb\u306e\u8a2d\u5b9a\u3084\u30bb\u30eb\u3078\u306e\u5024\u306e\u4ee3\u5165\u306a\u3069\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3084\u308a\u65b9\u306f\u3001\u6b21\u306e\u5199\u771f\u306e\u3088\u3046\u306b\u3001<span>Document Outline\u3067Collection View\u3092Control\u30ad\u30fc\u3092\u62bc\u3057\u306a\u304c\u3089\u30af\u30ea\u30c3\u30af\u3057\u3001<\/span><span class=\"marker-under-red\">ViewController<\/span><span>\u306b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3057\u307e\u3059\u3002<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_50_04-1024x729.jpg\" alt=\"\" width=\"880\" height=\"626\" class=\"alignnone wp-image-1269 size-large\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_50_04-1024x729.jpg 1024w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_50_04-300x214.jpg 300w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_50_04-768x547.jpg 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_50_04-1536x1093.jpg 1536w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_50_04-940x669.jpg 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_50_04.jpg 1800w\" sizes=\"(max-width: 880px) 100vw, 880px\"><\/p>\n<p><span>\u3059\u308b\u3068\u3001\u4e0b\u306e\u3088\u3046\u306bOutlets\u306e\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u3001<\/span><strong>\u300cdataSource\u300d\u3068\u300cdelegate\u300d<\/strong><span>\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_50_26.jpg\" alt=\"\" width=\"354\" height=\"246\" class=\"alignnone wp-image-1270 size-full\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_50_26.jpg 354w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_50_26-300x208.jpg 300w\" sizes=\"(max-width: 354px) 100vw, 354px\"><\/p>\n<p><span>\u304d\u3061\u3093\u3068\u9078\u629e\u3067\u304d\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u6b21\u306e\u5199\u771f\u306e\u3088\u3046\u306b\u300cdataSource\u300d\u3068\u300cdelegate\u300d\u306e\u5de6\u7aef\u306b\u767d\u4e38\u304c\u4ed8\u304d\u307e\u3059\u3002<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-14-13.50.44.png\" alt=\"\" width=\"388\" height=\"280\" class=\"alignnone wp-image-1271 size-full\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-14-13.50.44.png 388w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-14-13.50.44-300x216.png 300w\" sizes=\"(max-width: 388px) 100vw, 388px\"><\/p>\n<p><script src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\" async><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-4166043434922569\" data-ad-slot=\"7750996733\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-3\"><span id=\"CollectionViewCell\"><span id=\"TableViewCell\">CollectionViewCell\u306e\u8a2d\u5b9a\u3092\u3059\u308b<\/span><\/span><\/h2>\n<p>\u7d9a\u3044\u3066\u3001\u30bb\u30eb\u306e\u8a2d\u5b9a\u3092\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h3 id=\"i-4\"><span id=\"1_ID\"><span id=\"2_ID\">1. ID\u306e\u8a2d\u5b9a<\/span><\/span><\/h3>\n<p>Collection View\u3092\u8a2d\u7f6e\u3059\u308b\u3068\u81ea\u52d5\u7684\u306bCollectionViewCell\uff08\u30bb\u30eb\uff09\u3082\u8ffd\u52a0\u3055\u308c\u308b\u306e\u3067\u3001\u3053\u306e\u30bb\u30eb\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001\u30bb\u30eb\u306e\u540d\u524d\u306b\u5f53\u305f\u308bID\uff08<span>Identifier<\/span>\uff09\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_45_24-1024x487.jpg\" alt=\"\" width=\"880\" height=\"419\" class=\"wp-image-1272 size-large aligncenter\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_45_24-1024x487.jpg 1024w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_45_24-300x143.jpg 300w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_45_24-768x365.jpg 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_45_24-940x447.jpg 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_45_24.jpg 1190w\" sizes=\"(max-width: 880px) 100vw, 880px\"><\/p>\n<p>ID\u540d\u306f\u4f55\u3067\u3082\u3044\u3044\u3067\u3059\u304c\u3001\u308f\u304b\u308a\u3084\u3059\u3044\u3082\u306e\u306b\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u3053\u3053\u3067\u306f\u300cCell\u300d\u3068\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h3 id=\"i-5\"><span id=\"2_UILabel\"><span id=\"2_ID\">2. \u30bb\u30eb\u306bUILabel\u3092\u30bb\u30c3\u30c8\u3059\u308b<\/span><\/span><\/h3>\n<p>\u4eca\u56de\u306f\u30bb\u30eb\u306b\u30e9\u30d9\u30eb\u3092\u7f6e\u3044\u3066\u3001\u305d\u308c\u3092\u8868\u793a\u3059\u308b\u4f8b\u3092\u7d39\u4ecb\u3059\u308b\u305f\u3081UILabel\u3092\u30bb\u30eb\u306e\u4e2d\u306b\u8d77\u304d\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_46_51-1024x660.jpg\" alt=\"\" width=\"880\" height=\"567\" class=\"alignnone wp-image-1273 size-large\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_46_51-1024x660.jpg 1024w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_46_51-300x193.jpg 300w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_46_51-768x495.jpg 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_46_51-1536x990.jpg 1536w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_46_51-940x606.jpg 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_46_51.jpg 1992w\" sizes=\"(max-width: 880px) 100vw, 880px\"><\/p>\n<p>\u30bb\u30eb\u306e\u771f\u3093\u4e2d\u306b\u6765\u308b\u3088\u3046\u306b\u3001AutoLayout\u306e\u8a2d\u5b9a\u3082\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_01-970x1024.jpg\" alt=\"\" width=\"880\" height=\"929\" class=\"alignnone wp-image-1274 size-large\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_01-970x1024.jpg 970w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_01-284x300.jpg 284w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_01-768x811.jpg 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_01-940x993.jpg 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_01.jpg 1352w\" sizes=\"(max-width: 880px) 100vw, 880px\"><\/p>\n<h3 id=\"i-6\"><span id=\"3_tag\">3. tag\u306e\u8a2d\u5b9a<\/span><\/h3>\n<p>\u5f8c\u307b\u3069\u3001tag\u3092\u4f7f\u3063\u3066UILabel\u306b\u30c7\u30fc\u30bf\u3092\u30bb\u30c3\u30c8\u3059\u308b\u306e\u3067\u3001tag\u306b\u756a\u53f7\u3092\u632f\u3063\u3066\u304a\u304d\u307e\u3059\uff08\u4eca\u56de\u306f1\u3068\u3057\u307e\u3059\uff09\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_44-995x1024.jpg\" alt=\"\" width=\"880\" height=\"906\" class=\"alignnone wp-image-1281 size-large\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_44-995x1024.jpg 995w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_44-292x300.jpg 292w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_44-768x790.jpg 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_44-940x967.jpg 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_13_48_44.jpg 1248w\" sizes=\"(max-width: 880px) 100vw, 880px\"><\/p>\n<div class=\"memo \">\n<div class=\"memo_ttl dfont\"> MEMO<\/div>\n<p>\u4eca\u56de\u306e\u4f8b\u306fUILabel\uff11\u3064\u3060\u3051\u3067\u3059\u304c\u3001\u30bb\u30eb\u306e\u4e2d\u306b\u8907\u6570\u306eUI\u90e8\u54c1\u3092\u8a2d\u7f6e\u3059\u308b\u5834\u5408\u306f\u3001\u305d\u308c\u305e\u308c\u5225\u306e\u30bf\u30b0\u756a\u53f7\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<\/div>\n<h3 id=\"i-7\"><span id=\"4_Estimate_Size\"><span id=\"2_ID\">4. Estimate Size\u306e\u8a2d\u5b9a<\/span><\/span><\/h3>\n<p>\u30bb\u30eb\u304c\uff11\u3064\u306e\u3068\u304d\u306b\u3001Estimate Size\u304c\u60aa\u3055\u3092\u3057\u3066\u306a\u306e\u304b\u4e2d\u592e\u306b\u5bc4\u3063\u3066\u3057\u307e\u3046\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u304c\u5acc\u306a\u5834\u5408\u3001\u3053\u3061\u3089\u306e\u8a2d\u5b9a\u3092None\u306b\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_11_33-1024x361.jpg\" alt=\"\" width=\"880\" height=\"310\" class=\"alignnone wp-image-1277 size-large\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_11_33-1024x361.jpg 1024w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_11_33-300x106.jpg 300w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_11_33-768x270.jpg 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_11_33-940x331.jpg 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_11_33.jpg 1386w\" sizes=\"(max-width: 880px) 100vw, 880px\"><\/p>\n<h3 id=\"i-8\"><span id=\"5\"><span id=\"2_ID\">5. \u30bb\u30eb\u540c\u58eb\u306e\u4f59\u8a08\u306a\u30b9\u30da\u30fc\u30b9\u3092\uff10\u306b\u3057\u3066\u304a\u304f<\/span><\/span><\/h3>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u30bb\u30eb\u9593\u306b\u4f59\u8a08\u306a\u4f59\u767d\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4f59\u767d\u306f\u81ea\u5206\u3067\u8a2d\u5b9a\u3057\u305f\u3044\u306e\u3067\u3001\u4e0b\u306e\u300c<strong>Min Spacing<\/strong>\u300d\u3068\u3044\u3046\u9805\u76ee\u3092\uff10\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_26_33-1024x451.jpg\" alt=\"\" width=\"880\" height=\"388\" class=\"alignnone wp-image-1276 size-large\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_26_33-1024x451.jpg 1024w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_26_33-300x132.jpg 300w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_26_33-768x339.jpg 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_26_33-940x414.jpg 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8_2020-09-14_14_26_33.jpg 1320w\" sizes=\"(max-width: 880px) 100vw, 880px\"><\/p>\n<p>\u4ee5\u4e0a\u3067\u3001\u30bb\u30eb\u306e\u8a2d\u5b9a\u306f\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<p>\u6b21\u306f\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n<script src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\" async><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-4166043434922569\" data-ad-slot=\"7750996733\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-9\"><span id=\"ViewController\"><span id=\"ViewController\">ViewController\u3078\u306e\u8a18\u8ff0<\/span><\/span><\/h2>\n<p>\u3053\u3053\u3067\u306f\u3001Storyboard\u4e0a\u3067\u8a2d\u5b9a\u3057\u305fCollectionView\u3092\u8868\u793a\u3059\u308b\u305f\u3081\u306e\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>import UIKit\n\nclass ViewController: UIViewController {\n\n&nbsp; &nbsp; <code class=\" language-swift\">   <span class=\"token comment\">\/\/ 1.\u30bb\u30eb\u306b\u8868\u793a\u3059\u308b\u30c7\u30fc\u30bf\u3092\u6e96\u5099<\/span><\/code> &nbsp; let titleLabels: [String] = [\"title1\", \"title2\", \"title3\", \"title4\"] &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; override func viewDidLoad() { &nbsp; &nbsp; &nbsp; &nbsp; super.viewDidLoad()&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } } \/\/ 2 collectionView\u306b\u95a2\u3059\u308b\u8a2d\u5b9a extension ViewController: UICollectionViewDataSource { &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; \/\/ 2-1. \u30bb\u30af\u30b7\u30e7\u30f3\u6570 &nbsp; &nbsp; func numberOfSections(in collectionView: UICollectionView) -&gt; Int { &nbsp; &nbsp; &nbsp; &nbsp; return 1 &nbsp; &nbsp; } &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; \/\/ 2-2. \u30bb\u30eb\u6570 &nbsp; &nbsp; func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int { &nbsp; &nbsp; &nbsp; &nbsp; return titleLabels.count &nbsp; &nbsp; } &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; \/\/ 2-3. \u30bb\u30eb\u306b\u5024\u3092\u30bb\u30c3\u30c8 &nbsp; &nbsp; func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ widthReuseIdentifier\u306b\u306fStoryboard\u3067\u8a2d\u5b9a\u3057\u305f\u30bb\u30eb\u306eID\u3092\u6307\u5b9a &nbsp; &nbsp; &nbsp; &nbsp; let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \"Cell\", for: indexPath) &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u30bb\u30eb\u306e\u30e9\u30d9\u30eb\u306b\u5024\u3092\u30bb\u30c3\u30c8\u3002viewWithTag\u306b\u306f\u30bf\u30b0\u306e\u756a\u53f7\u3092\u6307\u5b9a &nbsp; &nbsp; &nbsp; &nbsp; let title = cell.contentView.viewWithTag(1) as! UILabel &nbsp; &nbsp; &nbsp; &nbsp; title.text = titleLabels[indexPath.row] &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u30bb\u30eb\u306b\u67a0\u7dda\u3092\u30bb\u30c3\u30c8 &nbsp; &nbsp; &nbsp; &nbsp; cell.layer.borderColor = UIColor.lightGray.cgColor \/\/ \u5916\u67a0\u306e\u8272 &nbsp; &nbsp; &nbsp; &nbsp; cell.layer.borderWidth = 1.0 \/\/ \u67a0\u7dda\u306e\u592a\u3055 &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return cell &nbsp; &nbsp; } } \/\/ 3. \u30bb\u30eb\u304c\u30bf\u30c3\u30d7\u3055\u308c\u305f\u6642\u306e\u51e6\u7406\u306a\u3069\uff08\u4eca\u56de\u306f\u5272\u611b\uff09 extension ViewController: UICollectionViewDelegate {&nbsp;&nbsp; &nbsp; }<\/code><\/pre>\n<\/div>\n<h3 id=\"i-10\"><span id=\"1\"><span id=\"1\">1. \u30bb\u30eb\u306b\u8868\u793a\u3059\u308b\u30c7\u30fc\u30bf\u3092\u6e96\u5099<\/span><\/span><\/h3>\n<p>\u307e\u305a\u306f\u30bb\u30eb\u306b\u8868\u793a\u3059\u308b\u305f\u3081\u306e\u30c7\u30fc\u30bf\u304c\u5fc5\u8981\u306a\u306e\u3067\u3001\u30c6\u30b9\u30c8\u7528\u306b\u914d\u5217\u3092\u7528\u610f\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers language-swift\" data-lang=\"Swift\"><code class=\" language-swift\"> <span class=\"token comment\">\/\/ 1.\u30bb\u30eb\u306b\u8868\u793a\u3059\u308b\u30c7\u30fc\u30bf\u3092\u6e96\u5099<\/span>\n<code>let titleLabels: [String] = [\"title1\", \"title2\", \"title3\", \"title4\"]<\/code><\/code><\/pre>\n<\/div>\n<h3 id=\"i-11\"><span id=\"2_collectionView\"><span id=\"2\">2. collectionView\u306e\u8868\u793a\u306b\u95a2\u9023\u3059\u308b\u51e6\u7406<\/span><\/span><\/h3>\n<p>\u7d9a\u3044\u3066\u3001collectionView\u306e\u8868\u793a\u306b\u95a2\u9023\u3059\u308b\u30d7\u30ed\u30c8\u30b3\u30eb\u300cUICollectionViewDataSource\u300d\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u300c<strong>class ViewController: UIViewController, UICollectionViewDataSource{}<\/strong>\u300d\u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u3082\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u6570\u304c\u5897\u3048\u308b\u3068\u3001\u53ef\u8aad\u6027\u304c\u60aa\u304f\u306a\u308b\u306e\u3067extension\u3067\u5225\u51fa\u3057\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers language-swift\" data-lang=\"Swift\"><code class=\" language-swift\"><span class=\"token comment\">\/\/ 2. \u30c6\u30fc\u30d6\u30eb\u30d3\u30e5\u30fc\u306b\u95a2\u3059\u308b\u8a2d\u5b9a<\/span>\n<span class=\"token keyword\">extension<\/span> <span class=\"token builtin\">ViewController<\/span><span class=\"token punctuation\">:<\/span> UICollectionViewDataSource <span class=\"token punctuation\">{<\/span>  \n\n<span class=\"token punctuation\">}<\/span><span aria-hidden=\"true\" class=\"line-numbers-rows\"><span><\/span><span><\/span><span><\/span><span><\/span><\/span><\/code><\/pre>\n<\/div>\n<p>\u4e2d\u306b\u306f\u6b21\u306e\uff13\u3064\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u66f8\u304d\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers language-swift\" data-lang=\"Swift\"><code class=\" language-swift\"><span class=\"token punctuation\"><code>\/\/ 2-1. \u30bb\u30af\u30b7\u30e7\u30f3\u6570\nfunc numberOfSections(in collectionView: UICollectionView) -&gt; Int {\n&nbsp; &nbsp; return 1\n}\n&nbsp;&nbsp; &nbsp;\n\/\/ 2-2. \u30bb\u30eb\u6570\nfunc collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {\n&nbsp; &nbsp; return titleLabels.count\n}\n&nbsp;&nbsp; &nbsp;\n\/\/ 2-3. \u30bb\u30eb\u306b\u5024\u3092\u30bb\u30c3\u30c8\nfunc collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {&nbsp;&nbsp; &nbsp; &nbsp;  \n&nbsp; &nbsp; \/\/ widthReuseIdentifier\u306b\u306fStoryboard\u3067\u8a2d\u5b9a\u3057\u305f\u30bb\u30eb\u306eID\u3092\u6307\u5b9a\n&nbsp; &nbsp; let cell = collectionView.dequeueReusableCell(withReuseIdentifier: \"Cell\", for: indexPath)\n&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\n&nbsp; &nbsp; \/\/ \u30bb\u30eb\u306e\u30e9\u30d9\u30eb\u306b\u5024\u3092\u30bb\u30c3\u30c8\u3002viewWithTag\u306b\u306f\u30bf\u30b0\u306e\u756a\u53f7\u3092\u6307\u5b9a\n&nbsp; &nbsp; let title = cell.contentView.viewWithTag(1) as! UILabel\n&nbsp; &nbsp; title.text = titleLabels[indexPath.row]\n\n&nbsp; &nbsp; \/\/ \u30bb\u30eb\u306b\u67a0\u7dda\u3092\u30bb\u30c3\u30c8\n&nbsp; &nbsp; cell.layer.borderColor = UIColor.lightGray.cgColor \/\/ \u5916\u67a0\u306e\u8272\n&nbsp; &nbsp; cell.layer.borderWidth = 1.0 \/\/ \u67a0\u7dda\u306e\u592a\u3055\n&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\n&nbsp; &nbsp; return cell\n}<\/code><\/span><\/code><\/pre>\n<\/div>\n<p><span>\u300c2-1\u300d\u306f\u30bb\u30af\u30b7\u30e7\u30f3\u306e\u6570\u3092\u8fd4\u3057\u307e\u3059\u3002\u4eca\u56de\u306f\uff11\u3064\u3060\u3051\u306a\u306e\u3067\u3001return 1\u3068\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n<p>\u300c2-2\u300d\u306f<span>\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b\u30bb\u30eb\u6570\u3092\u8fd4\u3057\u3066\u3044\u307e\u3059\u3002<\/span>\u914d\u5217titleLabels\u306e\u8981\u7d20\u6570\u5fc5\u8981\u306a\u306e\u3067\u3001\u300ctitleLabels.count\u300d\u3092\u8fd4\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u300c2-3\u300d\u3067\u306f\u3001\u30bb\u30eb\u306b\u8868\u793a\u3059\u308b\u5024\u3092\u30bb\u30c3\u30c8\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001<strong>collectionView.dequeueReusableCell(withReuseIdentifier: \u201cCell\u201d, for: indexPath)<\/strong> \u3067\u30bb\u30eb\u3092\u4f5c\u6210\u3057\u3001\u305d\u306e\u30bb\u30eb\u306b\u914d\u5217titleLabels\u306e\u5024\u3092\u683c\u7d0d\u3057\u3066\u8fd4\u5374\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u300cindexPath.row\u300d\u306f\u30bb\u30eb\u306e\u884c\u6570\u3092\u8868\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0a\u3067\u3001\u30d3\u30eb\u30c9\u3057\u30b7\u30df\u30e5\u30ec\u30fc\u30bf\u30fc\u3092\u8d77\u52d5\u3059\u308b\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u56db\u89d2\u306e\u30bb\u30eb\u304c\uff14\u3064\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u304c\u3001\u30d0\u30e9\u30f3\u30b9\u304c\u60aa\u304f\u898b\u6804\u3048\u306f\u3088\u304f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.16.32-581x1024.png\" alt=\"\" width=\"385\" height=\"679\" class=\"alignnone wp-image-1286 \" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.16.32-581x1024.png 581w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.16.32-170x300.png 170w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.16.32-768x1353.png 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.16.32-872x1536.png 872w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.16.32-940x1656.png 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.16.32.png 998w\" sizes=\"(max-width: 385px) 100vw, 385px\"><\/p>\n<p>&nbsp;<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u6b21\u306b\u30bb\u30eb\u306e\u30b5\u30a4\u30ba\u306e\u8abf\u6574\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3 id=\"i-12\"><span id=\"3\">3. \u30bb\u30eb\u306e\u30b5\u30a4\u30ba\u3092\u8abf\u6574\u3059\u308b<\/span><\/h3>\n<p><span>\u30bb\u30eb\u306e\u30b5\u30a4\u30ba\u8abf\u6574\u306b\u306f\u3001<span class=\"keiko_yellow\"><strong>UICollectionViewDelegateFlowLayout<\/strong><\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/span><span>\u3053\u308c\u3092\u4f7f\u3046\u3053\u3068\u3067\u753b\u9762\u30b5\u30a4\u30ba\u306b\u5408\u3063\u305f\u30bb\u30eb\u30b5\u30a4\u30ba\u3092\u8a08\u7b97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>\/\/ \u30bb\u30eb\u306e\u30b5\u30a4\u30ba\u3092\u8abf\u6574\u3059\u308b\nextension ViewController: UICollectionViewDelegateFlowLayout {\n\n&nbsp; &nbsp; \/\/ \u30bb\u30eb\u30b5\u30a4\u30ba\u3092\u6307\u5b9a\u3059\u308b\n&nbsp; &nbsp; func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {\n\n&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u6a2a\u65b9\u5411\u306e\u30b5\u30a4\u30ba\u3092\u8abf\u6574\n&nbsp; &nbsp; &nbsp; &nbsp; let cellSizeWidth:CGFloat = self.view.frame.width\/2\n    \n&nbsp; &nbsp; &nbsp; &nbsp; \/\/ width\u3068height\u306e\u30b5\u30a4\u30ba\u3092\u8fd4\u3059\n  &nbsp; &nbsp; &nbsp; return CGSize(width: cellSizeWidth, height: cellWidth\/2)\n&nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\n}<\/code><\/pre>\n<\/div>\n<p class=\"p2\">\u4eca\u56de\u306f\u6a2a\uff12\u5217\u3067\u30bb\u30eb\u3092\u4e26\u3079\u305f\u3044\u306e\u3067\u3001\u300cself.view.frame.width\/2\u300d\u3067\u30b9\u30af\u30fc\u30f3\u306e\u534a\u5206\u306e\u30b5\u30a4\u30ba\u3092\u53d6\u5f97\u3057\u3001\u305d\u308c\u3092return CGSize()\u3067\u8fd4\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u7e26\u306e\u9ad8\u3055\u306f\u3001\u6a2a\u5e45\u306e\u534a\u5206\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u308c\u3067\u30b7\u30df\u30e5\u30ec\u30fc\u30bf\u30fc\u3092\u7acb\u3061\u4e0a\u3052\u3066\u307f\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30d0\u30e9\u30f3\u30b9\u3088\u304f\u30bb\u30eb\u304c\u914d\u7f6e\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.26.14-581x1024.png\" alt=\"\" width=\"409\" height=\"721\" class=\"alignnone wp-image-1287 \" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.26.14-581x1024.png 581w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.26.14-170x300.png 170w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.26.14-768x1353.png 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.26.14-872x1536.png 872w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.26.14-940x1656.png 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.26.14.png 998w\" sizes=\"(max-width: 409px) 100vw, 409px\"><\/p>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-13\"><span id=\"i\"><span id=\"ViewController\">\u884c\u9593\u3092\u6307\u5b9a\u3057\u305f\u3044\u5834\u5408<\/span><\/span><\/h2>\n<p>\u884c\u9593\u3092\u8a2d\u5b9a\u3057\u305f\u3044\u5834\u5408\u306f\u3001<span><span class=\"keiko_yellow\"><strong>UICollectionViewDelegateFlowLayout <\/strong><\/span><\/span>\u5185\u306b\u6b21\u306e\u51e6\u7406\u3092\u52a0\u3048\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -&gt; CGFloat {\n&nbsp; &nbsp; &nbsp;return 15.0 \/\/ \u884c\u9593\n}<\/code><\/pre>\n<\/div>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.30.00-581x1024.png\" alt=\"\" width=\"413\" height=\"728\" class=\"alignnone wp-image-1288 \" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.30.00-581x1024.png 581w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.30.00-170x300.png 170w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.30.00-768x1353.png 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.30.00-872x1536.png 872w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.30.00-940x1656.png 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.30.00.png 998w\" sizes=\"(max-width: 413px) 100vw, 413px\"><\/p>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-14\"><span id=\"i-2\"><span id=\"ViewController\">\u30bb\u30eb\u306b\u4f59\u767d\u3092\u6301\u305f\u305b\u305f\u3044\u5834\u5408<\/span><\/span><\/h2>\n<p>\u30bb\u30eb\u306b\u4f59\u767d\u3092\u6301\u305f\u305b\u305f\u3044\u5834\u5408\u306f\u3001<span><span class=\"keiko_yellow\"><strong>UICollectionViewDelegateFlowLayout <\/strong><\/span><\/span>\u5185\u306b\u6b21\u306e\u51e6\u7406\u3092\u52a0\u3048\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -&gt; UIEdgeInsets {\n  return <span class=\"s1\">UIEdgeInsets<\/span>(top: <span class=\"s2\">0<\/span>, left: <span class=\"s2\">15<\/span>, bottom: <span class=\"s2\">0<\/span>, right: <span class=\"s2\">15<\/span>)\n}<\/code><\/pre>\n<\/div>\n<p class=\"p1\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.40.42-581x1024.png\" alt=\"\" width=\"407\" height=\"717\" class=\"alignnone wp-image-1289 \" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.40.42-581x1024.png 581w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.40.42-170x300.png 170w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.40.42-768x1353.png 768w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.40.42-872x1536.png 872w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.40.42-940x1656.png 940w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8-2020-09-15-10.40.42.png 998w\" sizes=\"(max-width: 407px) 100vw, 407px\"><\/p>\n<p>\u305f\u3060\u3057\u3001\u4e0a\u8a18\u306e\u4f8b\u306e\u5834\u5408\u3001\u5de6\u53f3\u306e\u4f59\u767d\u304c15\u305a\u3064\uff08\u5408\u8a0830\u5897\u3048\u308b\uff09\u306e\u3067\u3001\u30bb\u30eb\u306ewidth\u306e\u30b5\u30a4\u30ba\u309230\u5f15\u3044\u3066\u3042\u3052\u306a\u3044\u3068\u3001\uff11\u5217\u3067\u8868\u793a\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-swift\" data-lang=\"Swift\"><code>func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {\n\n &nbsp; let cellSizeWidth:CGFloat = self.view.frame.width\/2 - 30  \/\/\u3000\u4f59\u767d\u5206\uff0830\uff09\u3092\u5f15\u304f\n &nbsp;&nbsp;return CGSize(width: cellSizeWidth, height: cellSizeWidth\/3)\n}<\/code><\/pre>\n<\/div>\n<h2 class=\"hh hh5 pastel-bc\" id=\"i-15\"><span id=\"i-3\"><span id=\"ViewController\">\u30bb\u30af\u30b7\u30e7\u30f3\u3054\u3068\u306b\u30d8\u30c3\u30c0\u30fc\u3092\u4ed8\u3051\u305f\u3044\u5834\u5408<\/span><\/span><\/h2>\n<p>\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a class=\"linkto table\" href=\"https:\/\/naoya-ono.com\/swift\/collection-view-header\/\"><span class=\"tbcell tbimg\"><img loading=\"lazy\" width=\"160\" height=\"160\" src=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/uicollectionview-header-160x160.png\" class=\"attachment-thumb-160 size-thumb-160 wp-post-image\" alt=\"\" decoding=\"async\" srcset=\"https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/uicollectionview-header-160x160.png 160w, https:\/\/naoya-ono.com\/swift\/wp-content\/uploads\/2020\/09\/uicollectionview-header-150x150.png 150w\" sizes=\"(max-width: 160px) 100vw, 160px\"><\/span><span class=\"tbcell tbtext\">\u3010Swift\u3011CollectionView\u306b\u30d8\u30c3\u30c0\u30fc\u3092\u3064\u3051\u308b\u65b9\u6cd5<\/span><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u30da\u30fc\u30b8\u3067\u306f\u3001UICollectionView\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b\u307e\u3067\u306e\u57fa\u672c\u7684\u306a\u6d41\u308c\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002 UITableView\u3068\u5c11\u3057\u4f3c\u3066\u3044\u308b\u306e\u3067\u3001\u3053\u3061\u3089\u306e\u4f7f\u3044\u65b9\u304c\u7406\u89e3\u3067\u304d\u3066\u3044\u308c\u3070\u3001UICollectionV &#8230; <\/p>\n","protected":false},"author":1,"featured_media":1294,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,9],"tags":[],"_links":{"self":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts\/1262"}],"collection":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/comments?post=1262"}],"version-history":[{"count":17,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts\/1262\/revisions"}],"predecessor-version":[{"id":1314,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/posts\/1262\/revisions\/1314"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/media\/1294"}],"wp:attachment":[{"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/media?parent=1262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/categories?post=1262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/naoya-ono.com\/swift\/wp-json\/wp\/v2\/tags?post=1262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}