我有一个简单的难题。我的应用程序中有一个 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/