【发布时间】:2020-01-30 03:56:54
【问题描述】:
我正在尝试通过新的 iOS 13 上下文菜单为我的应用程序实现一个简单的报告/阻止功能。它似乎工作正常,但是,我目前无法解决它的外观问题。
- 当我长按
UICollectionViewCell时,它会在黑暗模式下突出显示黑色,这看起来很糟糕,因为我没有全黑背景色。如何将其更改为清晰的颜色或我想要的颜色? - 我有一个显示用户消息的气泡,我想使用气泡的上下文菜单。问题是,当上下文菜单默认预览我的单元格时,它会裁剪气泡的底部,看起来只是整个消息的一部分。我尝试使用单元格的高度和其他一些参数 - 没有任何效果。
如何解决这些问题?请帮忙。
****我的代码是:****
@available(iOS 13.0, *)
override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil){ action in
let cell = collectionView.cellForItem(at: IndexPath.init(row: indexPath.row, section: 0)) as? ChatCell
cell?.tintColor = .clear
self.view.backgroundColor = .clear
let messageText = cell?.textView.text
let userNameZdes = cell?.nameView.text
let report = UIAction(title: "Report", image: UIImage(systemName: "exclamationmark.bubble"), identifier: UIAction.Identifier(rawValue: "report")) {_ in
print("report clicked..")
if (cell?.textView.text.count)! > 2 {
print("the text of the message = \(messageText!) & the user is \(userNameZdes!)")
} else {
print("the user has attached a bad pic")
}
}
let block = UIAction(title: "Block user", image: UIImage(systemName: "person.crop.circle.badge.xmark"), identifier: UIAction.Identifier(rawValue: "block"), attributes: .destructive) {_ in
print("block clicked..")
}
return UIMenu(title: "Message Actions", image: nil, identifier: nil, children: [report, block])
}
return configuration
}
【问题讨论】:
-
如果要自定义默认预览,则必须在 UIContextMenuConfiguration(identifier: nil, previewProvider: nil) 中提供 previewProvider。另一方面,UICollectionViewCell 的选择颜色也是可自定义的。
标签: ios swift iphone uicollectionview ios13