ios - 上下文菜单选择颜色和框架大小 Swift 5 iOS 13
问题描述
我正在尝试通过新的 iOS 13 上下文菜单为我的应用程序实现一个简单的报告/阻止功能。它似乎工作正常,但是,我目前无法解决它的外观问题。
- 当我长按 a
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
}
解决方案
我今天遇到了同样的困难,我找到了一个对我有用的解决方案,所以我希望它也对你有用。
我在这篇文章中找到了解决方案:https ://kylebashour.com/posts/context-menu-guide
如果您向下滚动到该部分:UITargetedPreview
,有一个示例,UITableView
但是您可以为 UICollectionView 应用相同的解决方案:)
推荐阅读
- python - 将 Django 数据库从 SQLite3 更改为 PostgreSQL 后出错
- r - R中的条件行总和
- java - Intellij IDEA maven 远程存储库错误
- user-interface - 为什么不鼓励从代码中移动 GUI 窗口?
- syntax - ^ SyntaxError: 无效的语法
- visual-studio-code - Live Sass 编译器未编译
- reactjs - 无法在 useEffect 中对未安装的组件执行 React 状态更新
- java - 未显示通知并崩溃说 RemoteServiceException
- java - 如何添加它首先删除节点并删除节点最后
- flutter - 使用 Bloc 刷新 Flutter 中的对话框