【发布时间】:2016-09-14 05:52:32
【问题描述】:
我正在开发我的应用程序,在该应用程序中,我必须在选择时将图像添加到集合视图单元格。集合视图单元格是圆形的并填充有颜色,因此在选择单元格时,刻度的图像应该在该颜色上。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
NSArray *hexaColor= _advantageModelObj.productDetail.carColorDetails;
CarColorDetailObject *carColor= [hexaColor objectAtIndex:indexPath.row];
NSString *hexCode= carColor.carColor.hexCode;
cell.layer.masksToBounds=TRUE;
cell.backgroundColor=[self colorWithHexString:hexCode];
cell.layer.cornerRadius= (roundf(cell.frame.size.width/2));
cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"colorselected.png"]];
return cell;
}
【问题讨论】:
-
向我们展示您尝试过的代码。
-
这里也显示一些屏幕截图以了解您的需求
-
所以我有圆形单元格的集合视图,所以从 api 我已经将颜色填充到单元格,所以现在单击该单元格时,必须将显示其选定的图像添加到单元格中,因此背景颜色也是可见
标签: ios collections view