我正在UICollectionViewCell上实现UIContextMenu。在UICollectionViewCell内部,有一个半径为15的按钮。当我点击UICollectionViewCell时,这就是结果
。我想要的只是没有白色背景的按钮。我已经尝试过UICollectionViewCell.backgroundColor = .clear
,但似乎无法正常工作。如果有人可以帮助我,谢谢!
答案 0 :(得分:3)
在let identifier = "\(indexPath.row)" as NSString
函数中添加collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration?
。
将该标识符放入UIContextMenuConfiguration(identifier: identifier, previewProvider: previewProvider, actionProvider: actionProvider)
初始化中。
接下来添加此功能
func collectionView(_ collectionView: UICollectionView, previewForHighlightingContextMenuWithConfiguration configuration: UIContextMenuConfiguration) -> UITargetedPreview? {
guard
let identifier = configuration.identifier as? String,
let index = Int(identifier),
let cell = collectionView.cellForItem(at: IndexPath(row: index, section: 0)) as? YourCell
else {
return nil
}
return UITargetedPreview(view: cell.YourButton)
}
答案 1 :(得分:0)
您有 UIPreviewParameters
可以轻松更改 backgroundColor
。
答案 2 :(得分:-1)