我的应用程序中有一个照片库。我可以在其中选择多张照片并删除它们。一切进展顺利。
我只需要实现苹果的默认选择行为,正如我们在相机胶卷中看到的那样。
现在我的选择是这样的
我已经实现了 didSelectItemAtIndexPath 方法,如下 -
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Delegate cell %@ : SELECTED", [self formatIndexPath:indexPath]);
MyCustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.label.backgroundColor=[UIColor greenColor];
}
- (NSString *)formatIndexPath:(NSIndexPath *)indexPath
{
return [NSString stringWithFormat:@"%ld", (long)indexPath.row+1];
}
在MyCustomCell.m中,我将标签的框架设置为矩形,如图(绿色)所示。
方法 setSelected 如下所示:
- (void)setSelected:(BOOL)selected
{
UIView *blurView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 70)];
blurView.backgroundColor=[UIColor whiteColor];
blurView.alpha=0.5;
blurView.opaque=YES;
if (selected) {
self.label.backgroundColor = [UIColor greenColor];
[self.imageThumb addSubview:blurView];
}
}
那么,是否有可能拥有苹果的默认选择行为??
任何帮助将不胜感激。提前致谢。
最佳答案
在 setSelected:
如果选择的话,您的单元格的值为 YES
然后添加一个白色UIView
alpha 为0.5
(或将值调整为适合您的不透明度);如果NO
,删除该覆盖 View 。然后,当您添加复选标记图像时,请确保将其放置在覆盖 View 的顶部 [self.contentView bringSubviewToFront:checkmarkImageView]
.
关于iphone - UICollectionViewCell 选择行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16209091/