ios - 如何选择和突出显示像 UITableViewCell 这样的 UICollectionView?

标签 ios objective-c uicollectionviewcell highlight

我有一个简单的难题。我的应用程序中有一个 UICollectionViewController,它显示已保存的测验。我有正确的加载,但我希望它移动检测其中之一的点击,然后执行逻辑将其加载到主 VC 中。我希望选择类似于 UITableViewCell,它突出显示它一秒钟然后取消突出显示。如果有帮助,我正在使用子类化的 UICollectionViewCell。

最佳答案

为了突出显示,您可以像这样子类化您的单元格:

import UIKit

class CustomCell: UICollectionViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()

        let backgroundView = UIView(frame: CGRectZero)

        backgroundView.backgroundColor = UIColor.blueColor()

        self.selectedBackgroundView = backgroundView
    }
}

来自 the docs对于 UICollectionViewCell:

You can use this view to give the cell a custom appearance when it is selected. When the cell is selected, this view is layered above the backgroundView and behind the contentView.

关于ios - 如何选择和突出显示像 UITableViewCell 这样的 UICollectionView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33226356/

相关文章:

iphone - 如何使用 NSArray 中存储的位置数据创建图像和标签

objective-c - UIImageView,使用 easeIn easeInOut 过渡动画动画图像

swift - 无法从 UITableViewCell 显示 View Controller

swift - 单元格未出现在 UICollectionView 中?

ios - 快速自动布局+尺寸等级问题

ios - 如何更改 UIWebView 中 dataDetectorType 链接的颜色?

ios - 覆盖 touchesBegan : Error - method does not override any method from superclass

iphone - 检测 iOS 中 UITextField 中的回车符

ios - 计算在collectionView单元格中使用的NSString高度

ios - 具有输入和输出一维数据缓冲区的 Metal 计算着色器?