如何在iOS 11中为大型标题NavigationBar设置自定义背景图像?我正在使用我已分配给故事板中的navigationControllers的自定义子类.
这是我创建自定义NavBar的方法:
class CustomNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.navigationBar.tintColor = UIColor(red:1, green:1, blue:1, alpha:0.6)
self.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
if #available(iOS 11.0, *) {
self.navigationBar.prefersLargeTitles = true
self.navigationItem.largeTitleDisplayMode = .automatic
self.navigationBar.largeTitleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
self.navigationBar.barTintColor = UIColor.green
}
self.navigationBar.isTranslucent = false
self.navigationBar.setBackgroundImage(#imageLiteral(resourceName: "navigationBarBackground"), for: .default)
self.navigationBar.shadowImage = #imageLiteral(resourceName: "navigationBarShadow")
}
}
Run Code Online (Sandbox Code Playgroud)
奇怪的setBackgroundImage(image, for: .default)
是,这对大型游戏不起作用.以前在iOS 10上工作过,如果我旋转iPhone(并激活小型NavBar)背景又回来了吗?
编辑:
在backgroundImage
仍然呈现,但不知隐藏.仅当您开始滚动并出现"普通"导航栏时,才会看到backgroundImage.另外,barTintColor
完全是在这种情况下被忽略.
我想将自定义枚举保存到我的SwiftData模型中。我可以让它工作,它显示甚至更新 UI 中的值。不过,重新启动应用程序时,枚举变量/实体的更改 \xe2\x80\x99t 仍然存在!
\n使用自定义枚举时需要注意什么有什么建议吗?
\nenum Type: Int, Codable {\n case foo = 0\n case bar = 1\n}\n\n@Model\nfinal public class Item {\n var type: Type\n}\n
Run Code Online (Sandbox Code Playgroud)\nstruct DetailView: View {\n @Bindable var item: Item\n \n // MARK: -\n var body: some View {\n Picker("Type", selection: $item.type) {\n Text("Foo").tag(Type.foo)\n Text("Bar").tag(Type.bar)\n }\n .pickerStyle(.segmented)\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n 我刚刚从MAS下载了最新的Xcode 8.3.3更新.我想知道如何添加对新的10.5英寸iPad Pro的支持?
我正在使用具有自动布局的故事板,启动屏幕故事板以及所有应用程序图标大小都添加到xcassets中.
有没有办法获得 Siri 的声音NSSpeechSynthesizer
?NSSpeechSynthesizer.availableVoices()
没有列出它们,但也许有一个未记录的技巧或什么?
我也尝试过使用AVSpeech?Synthesizer
,即使它应该可以在 macOS 10.14+ 上使用,但我无法大声朗读……
我已经使用 Playground 使用来自NSHipster的以下代码对此进行了测试:
import Cocoa
import AVFoundation
let string = "Hello, World!"
let utterance = AVSpeechUtterance(string: string)
let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(utterance)
Run Code Online (Sandbox Code Playgroud) macos avfoundation avspeechsynthesizer swift nsspeechsynthesizer
我想.insetGrouped
仅在 iPad 上或基于尺寸变化特征使用新的 iOS 13 表格视图样式。
遗憾的是,在初始化之后无法更改 UITableView 样式:https : //developer.apple.com/documentation/uikit/uitableview/style
在情节提要中更改它也是没有选择的,因为无法根据大小类别更改它。
我目前正在使用此代码,但没有任何改变:
class DetailViewController: UITableViewController {
[…]
override init(style: UITableView.Style) {
if UIDevice.current.userInterfaceIdiom == .pad {
super.init(style: .insetGrouped)
} else {
super.init(style: style)
}
}
// Xcode forced me to include this as well?
required init?(coder: NSCoder) {
super.init(coder: coder)
}
}
Run Code Online (Sandbox Code Playgroud) 我的几个 SwiftUI 预览中有一堆字符串,但问题是它们包含在 Xcode导出本地化功能中。有没有办法自动阻止PreviewProvider
\xe2\x80\x99s 中的字符串导出进行本地化?
我\xe2\x80\x99ve已经尝试将PreviewProvider
结构包装在 中#if DEBUG
,但是那\xe2\x80\x99不起作用。
Text(verbatim: "")
String("")
不过,以这种方式包装所有预览字符串确实很烦人。我不可能\xe2\x80\x99 是唯一想要排除预览字符串的人,对吧?
\n我\xe2\x80\x99m 致力于支持 iOS 17\xe2\x80\x99s 新的快捷方式功能。我有多个应用程序快捷方式,包括一个在选定选项卡中启动应用程序的快捷方式。选项卡选择是通过AppView
符合AppEnum
协议的自定义枚举完成的。
问题是,由于某种原因,在视图 XYZ 中打开操作无法在 Spotlight 中正确显示\xe2\x80\x99。正如您在下面的屏幕截图中看到的,它没有任何图标或标题。此外,在“快捷方式”应用程序本身中,仅显示第一个短语产生的操作。基于短语的操作AppView
仅显示为下面的旧应用程序快捷方式。
知道如何解决这个问题吗?
\nstruct AppShortcuts: AppShortcutsProvider {\n static var shortcutTileColor: ShortcutTileColor = .grape\n \n static var appShortcuts: [AppShortcut] {\n AppShortcut(\n intent: OpenAppIntent(),\n phrases: [\n "Open \\(.applicationName)",\n "Open \\(\\.$view) in \\(.applicationName)"\n ],\n shortTitle: "Open",\n systemImageName: "arrow.up.forward.app"\n )\n // Other App Shortcuts \xe2\x80\xa6\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\nAppView
应用枚举extension AppView: AppEnum {\n static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "View")\n \n static var caseDisplayRepresentations: [Self …
Run Code Online (Sandbox Code Playgroud) I\xe2\x80\x99m 创建一个简单的 AppIntents 快捷方式,需要 UIKit 在我的应用程序中打开 URL。不过,一旦我将 添加import UIKit
到我的文件中,Xcode 就会在 处显示以下警告caseDisplayRepresentations
,因为我使用图像来显示表示。无需导入 UIKit(或无需 DisplayRepresentations 的图像),一切正常!有什么想法如何解决这个问题吗?
\n\n\n期望直接调用
\nImage
初始化程序,但得到Swift.Optional<AppIntents.DisplayRepresentation.Image>
了
import AppIntents\nimport UIKit\n\nenum AppView: Int, AppEnum {\n case tab1\n case tab2\n \n static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "View")\n \n static var caseDisplayRepresentations: [AppView : DisplayRepresentation] = [\n .tab1: DisplayRepresentation(title: "Tab 1",\n image: .init(systemName: "1.circle")),\n .tab2: DisplayRepresentation(title: "Tab 2",\n image: .init(systemName: "2.circle"))\n ]\n}\n\n// MARK: - Intent\nstruct OpenAppIntent: AppIntent {\n …
Run Code Online (Sandbox Code Playgroud) swift ×7
ios ×4
appintents ×2
ios11 ×2
swiftui ×2
xcode ×2
avfoundation ×1
ios10 ×1
ios13 ×1
ios17 ×1
localization ×1
macos ×1
swift-data ×1