ios - 可以在 UICollectionView 中自定义单元格吗?

标签 ios objective-c cell uicollectionview customizing

经过几个小时的谷歌搜索,我没有找到解决方案..

我想将这些属性添加到单元格,但这段代码不起作用

AppCell *cell = [[AppCell alloc] init];

cell.layer.cornerRadius = 5.0;
cell.layer.shadowColor = [[UIColor blackColor] CGColor];
cell.layer.shadowOpacity = 1.0;
cell.layer.shadowRadius = 10.0;
cell.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);

解决办法是什么?? .. 非常感谢您提前

最佳答案

首先,创建一个 CustomCell,它是 UICollectionViewCell 的子类。然后,将该 CustomCell.h 文件导入到您的 collectionView 的 Controller 中。

如果你想在一些单元格上设置这些属性,使用委托(delegate)方法 - (UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath

如果你想为所有单元格设置这些属性,只需将它们放在 CustomCell.m 中。记住导入 QuartzCore 框架。

关于ios - 可以在 UICollectionView 中自定义单元格吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16379828/

相关文章:

ios - 我如何在嵌入 UINavigationController 的另一个 Storyboard 上以模态方式呈现 UIViewController?

ios - cURL 请求有效,但不是等效的 NSURLSession 请求

css - 使用 setCellStyleGenerator 时表 propertyId 值为 null

performance - 在 Matlab 中使用非连续整数作为单元格或结构中的标识符

jquery - 如何使用 jQuery 获取表格单元格值

iphone - 如果指南针不准确,我该怎么办

javascript - 对于 IOS Phonegap 应用程序,是否可以包含非应用程序本地的 javascript 文件

iphone - iPhone 上的 Coredata,一个请求中的 setFetchBatchSize 和 setPropertiesToFetch

iphone - 使用 segue 和 Storyboard从一个 Controller 移动到另一个 Controller

iphone - 静态标题/导航栏?