繁体   English   中英

启用以快速获取sizeForItemAtIndexPath中的集合视图Cell对象

[英]Enable to get collection view Cell object in sizeForItemAtIndexPath in swift

像在Objective中一样,我们可以如下获取Collection View Cell的对象。 与Swift有一些问题

-(void)collectionView:(UICollectionView *)collectionView 
   didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

DatasetCell *datasetCell = 
  (DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath];

[datasetCell replaceHeaderGradientWith:[UIColor skyBlueHeaderGradient]];
datasetCell.backgroundColor = [UIColor skyBlueColor]; }

尝试这个 :

 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

let datasetCell =  collectionView(collectionView, cellForItemAtIndexPath: indexPath) as DatasetCell
datasetCell.backgroundColor = UIColor.blueColor()

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM