在 iOS 13 中,苹果自己的应用程序在搜索栏中包含麦克风按钮(例如,参见附图),允许用户直接开始语音听写,而不必先打开键盘并从那里开始。
是否也可以将麦克风按钮添加到我们应用程序的搜索栏中?我找不到任何相关的UISearchBar
API UITextField
。
我的应用程序支持 iOS 13 暗模式,并为用户提供匹配系统外观或强制应用程序始终使用暗模式或亮模式的选项,而不管系统设置如何。
该应用程序还允许在用户按下 时显示上下文菜单UILabel
。但是,当使用UIContextMenuInteractionDelegate
方法呈现上下文菜单时,我找不到任何方法来覆盖菜单的深色/浅色外观,也找不到UITargetedPreview
在上下文菜单出现和消失时动画的视图外观。
例如,如果 iOS 外观设置为浅色模式并且用户在应用程序中选择强制深色模式的选项,则上下文菜单显示为浅色。我想覆盖该行为,使它们看起来很暗 - 有什么方法可以实现这一目标吗?我似乎找不到overrideUserInterfaceStyle
与上下文菜单相关的属性。
我使用的代码如下供参考。
// Setup code
if #available(iOS 13.0, *) {
self.textLabel.addInteraction(UIContextMenuInteraction(delegate: self))
}
// UIContextMenuInteractionDelegate
@available(iOS 13.0, *)
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
let text = self.text
return UIContextMenuConfiguration(identifier: nil, previewProvider: { return TextViewController(text: text) }) { [weak self] _ in
return self?.contextMenu(for: text)
}
}
@available(iOS 13.0, *)
private func contextMenu(for text: String) -> UIMenu { …
Run Code Online (Sandbox Code Playgroud)