{"rsdb":{"rid":"377746","subhead":"","postdate":"0","aid":"264293","fid":"89","uid":"1","topic":"1","content":"
\n

\u5f15\u8a00<\/h1> \n

UICollectionView \u662f iOS \u5e73\u53f0\u4e0a\u4e00\u79cd\u5f3a\u5927\u7684\u89c6\u56fe\u5e03\u5c40\u5de5\u5177\uff0c\u80fd\u591f\u5f88\u597d\u5730\u5b9e\u73b0\u7f51\u683c\u5e03\u5c40\uff0c\u5217\u8868\u5e03\u5c40\u7b49\u591a\u79cd\u5e03\u5c40\u65b9\u5f0f\u3002<\/p> \n

\u9996\u5148\u8bb2\u4e0b\u4eca\u5929\u7684\u76ee\u6807\uff0c\u6211\u4eec\u5c06\u8981\u4f7f\u7528 UICollectionView \u6765\u521b\u5efa\u4eff\u5fae\u535a\u7684\u4e5d\u5bab\u683c\u5185\u5bb9\u3002\u9996\u5148\uff0c\u76ee\u6807\u884c\u6570\u4e3a3\uff0c\u6bcf\u884c\u663e\u793a3\u5f20\u56fe\u7247\uff0c\u603b\u5171\u663e\u793a9\u5f20\u56fe\u7247\u3002<\/p> \n

\u5b9e\u73b0\u65b9\u5f0f<\/h1> \n

\u6211\u4eec\u5f80\u754c\u9762\u4e0a\u6dfb\u52a0\u4e00\u4e2a UICollectionView\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a UICollectionViewFlowLayout \u5e03\u5c40\u7c7b\uff0c\u8fd9\u91cc\u7684\u5b9e\u73b0\u4e3a\u61d2\u52a0\u8f7d\u7684\u65b9\u5f0f\uff1a<\/p> \n

- (UICollectionView *)collectionView {\n    if (!_collectionView) {\n\t    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];\n        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];\n        _collectionView.scrollEnabled = NO; \/\/ \u8bbe\u7f6e\u4e0d\u8ba9\u6ed1\u52a8\n        [self.view addSubview:_collectionView];\n    }\n    return _collectionView;\n}\n<\/code><\/pre> \n 

\u4e3a\u81ea\u5b9a\u4e49 cell \u6ce8\u518c\u5230 UICollectionView \u4e2d\uff1a<\/p> \n

[_collectionView registerClass:[GCImageGridCell class] forCellWithReuseIdentifier:kGCImageGridCell];\n<\/code><\/pre> \n 

\u7136\u540e\uff0c\u6211\u4eec\u8bbe\u7f6e UICollectionView \u7684\u6570\u636e\u6e90\u534f\u8bae\uff1a<\/p> \n

_collectionView.dataSource = self;\n<\/code><\/pre> \n 

\u63a5\u7740\u5b9e\u73b0 UICollectionView \u7684\u534f\u8bae\u5185\u5bb9\uff1a<\/p> \n

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {\n    return self.datas.count;\n}\n\n- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {\n    GCImageGridCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kGCImageGridCell forIndexPath:indexPath];\n    NSString *imgName = self.datas[indexPath.row];\n    cell.imgView.image = [UIImage imageNamed:imgName];\n    return cell;\n}\n<\/code><\/pre> \n 

\u63a5\u7740\uff0c\u8bbe\u7f6e\u524d\u9762\u7684 UICollectionViewFlowLayout \u7684\u5c5e\u6027\uff0c\u5c06\u6ed1\u52a8\u7684\u65b9\u5411\u8bbe\u7f6e\u4e3a\u7eb5\u5411\u6ed1\u52a8\uff1a<\/p> \n

layout.scrollDirection = UICollectionViewScrollDirectionVertical; \/\/\u8bbe\u7f6e\u5e03\u5c40\u65b9\u5f0f\u4e3a\u7eb5\u5411\u5e03\u5c40\n<\/code><\/pre> \n 

\u63a5\u4e0b\u6765\uff0c\u8ba1\u7b97\u6bcf\u4e2a item \u7684\u5927\u5c0f\u3001item \u4e4b\u95f4\u7684\u95f4\u8ddd\u548c\u884c\u8ddd\u3001\u6bcf\u4e2a\u5206\u7ec4\u4e4b\u95f4\u7684\u95f4\u8ddd\uff1a<\/p> \n

CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;\nCGFloat horizontal = 16; \/\/ \u5de6\u53f3\u8fb9\u8ddd\nCGFloat itemSpace = 6; \/\/ item \u7684\u95f4\u8ddd\nCGFloat itemSize = (screenWidth - horizontal * 2 - itemSpace * 2) \/ 3; \/\/ \u8ba1\u7b97\u6bcf\u4e2a item \u7684\u5927\u5c0f\nlayout.minimumLineSpacing = itemSpace;\nlayout.minimumInteritemSpacing = itemSpace;\nlayout.sectionInset = UIEdgeInsetsMake(0, horizontal, 0, horizontal);\nlayout.itemSize = CGSizeMake(floor(itemSize), floor(itemSize));\n<\/code><\/pre> \n 
\n

\u6ce8\u610f\uff1a\u8ba1\u7b97item\u5927\u5c0f\u65f6\u4f7f\u7528\u5230\u4e86floor\u51fd\u6570\u5411\u4e0b\u53d6\u6574\uff0c\u8fd9\u662f\u9632\u6b62\u6bcf\u884c\u7684 item \u6709\u8d85\u51fa\u5c4f\u5e55\u800c\u5bfc\u81f4\u6362\u884c\u7684\u95ee\u9898<\/p> \n <\/blockquote> \n

\u6548\u679c\u5448\u73b0<\/h1> \n

\"\"<\/p> \n

\u603b\u7ed3<\/h1> \n

\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5b66\u4e60\u4e86\u5982\u4f55\u7528 UICollectionView \u6765\u5236\u4f5c\u4e5d\u5bab\u683c\u5e03\u5c40\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u4e3a\u5927\u5bb6\u5e26\u6765\u5e2e\u52a9\uff0c\u5feb\u6765\u5173\u6ce8\u6211\uff0c\u8ba9\u6211\u4eec\u4e00\u8d77\u52aa\u529b\uff01<\/p> \n

\u5173\u4e8e\u4f5c\u8005<\/h1> \n

\u535a\u6587\u4f5c\u8005\uff1aGarveyCalvin<\/p> \n

\u516c\u4f17\u53f7\uff1a\u51e1\u4eba\u7a0b\u5e8f\u733f<\/p> \n

\u5fae\u535a\uff1ahttps:\/\/weibo.com\/feiyueharia<\/a><\/p> \n

\u535a\u5ba2\u56ed\uff1ahttps:\/\/www.cnblogs.com\/GarveyCalvin<\/a><\/p> \n

\u672c\u6587\u7248\u6743\u5f52\u4f5c\u8005\u6240\u6709\uff0c\u6b22\u8fce\u8f6c\u8f7d\uff0c\u4f46\u5fc5\u987b\u4fdd\u7559\u6b64\u6bb5\u58f0\u660e\uff0c\u5e76\u7ed9\u51fa\u539f\u6587\u94fe\u63a5\uff0c\u8c22\u8c22\u5408\u4f5c\uff01<\/p> \n<\/div>","orderid":"0","title":"\u7ed9\u6211\u4e24\u5206\u949f\u7684\u65f6\u95f4\uff1a\u5fae\u535a\u98ce\u683c\u4e5d\u5bab\u683c\uff1aUICollectionView\u5b9e\u73b0","smalltitle":"","mid":"0","fname":"Swift","special_id":"0","bak_id":"0","info":"0","hits":"308","pages":"1","comments":"0","posttime":"2023-07-23 13:24:50","list":"1690089890","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u4e24\u5206<\/A> \u949f\u7684\u65f6<\/A> \u5bab\u683c<\/A> UICollectionView<\/A> \u5b9e\u73b0<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"119.59.235.169","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u7ed9\u6211\u4e24\u5206\u949f\u7684\u65f6\u95f4\uff1a\u5fae\u535a\u98ce\u683c\u4e5d\u5bab\u683c\uff1aUICollectionView\u5b9e\u73b0","lastview":"1715047636","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}