我是材料设计的新手。我有自定义 collectionView 单元格Main.storyboard
,其中包含一些标签、按钮和 Imageview。我想将我的自定义单元格加载为MDCCardCollectionCell
.
当我使用此代码时,我得到了空的MDCCardCollectionCell
. 它使应用程序崩溃
collectionView.register(MDCCardCollectionCell.self, forCellWithReuseIdentifier: "Cell")
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell",
for: indexPath) as! MDCCardCollectionCell
cell.cornerRadius = 8
cell.setShadowElevation(6, for: .selected)
cell.setShadowColor(UIColor.black, for: .highlighted)
return cell
}
当我在没有此行的情况下加载自定义 collectionView 单元格时,它已成功加载,Main.storyboard
但MDCCard
样式未应用(阴影效果)。
collectionView.register(MDCCardCollectionCell.self, forCellWithReuseIdentifier: "Cell")
谢谢