小编ale*_*ner的帖子

在iOS 11中使用大标题NavigationBar自定义背景图像

如何在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完全是在这种情况下被忽略. 截图 GIF

uinavigationbar ios swift ios11

21
推荐指数
3
解决办法
9326
查看次数

如何使用 SwiftData 保存自定义枚举?

我想将自定义枚举保存到我的SwiftData模型中。我可以让它工作,它显示甚至更新 UI 中的值。不过,重新启动应用程序时,枚举变量/实体的更改 \xe2\x80\x99t 仍然存在!

\n

使用自定义枚举时需要注意什么有什么建议吗?

\n

我的模特

\n
enum 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)\n

用户界面代码

\n
struct 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

swift swift-data swiftui

17
推荐指数
2
解决办法
4173
查看次数

如何添加对10.5英寸iPad Pro的支持

我刚刚从MAS下载了最新的Xcode 8.3.3更新.我想知道如何添加对新的10.5英寸iPad Pro的支持?

我正在使用具有自动布局的故事板,启动屏幕故事板以及所有应用程序图标大小都添加到xcassets中.

xcode ios-simulator ios10 ios11

15
推荐指数
1
解决办法
3785
查看次数

NSSpeechSynthesizer 在 macOS 上获取 Siri 声音

有没有办法获得 Siri 的声音NSSpeechSynthesizerNSSpeechSynthesizer.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

10
推荐指数
1
解决办法
576
查看次数

根据设备/特征将 UITableView.Style 设置为 .insetGrouped

我想.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)

ios swift ios13

6
推荐指数
1
解决办法
1637
查看次数

从本地化导出中排除预览中的字符串

我的几个 SwiftUI 预览中有一堆字符串,但问题是它们包含在 Xcode导出本地化功能中。有没有办法自动阻止PreviewProvider\xe2\x80\x99s 中的字符串导出进行本地化?

\n

我\xe2\x80\x99ve已经尝试将PreviewProvider结构包装在 中#if DEBUG,但是那\xe2\x80\x99不起作用。

\n

我目前的解决方法

\n
    \n
  1. 使用Text(verbatim: "")
  2. \n
  3. 将其他字符串包裹起来String("")
  4. \n
\n

不过,以这种方式包装所有预览字符串确实很烦人。我不可能\xe2\x80\x99 是唯一想要排除预览字符串的人,对吧?

\n

xcode localization swift swiftui

6
推荐指数
1
解决办法
373
查看次数

参数化应用程序快捷方式未在 Spotlight 中正确显示 (iOS 17)

我\xe2\x80\x99m 致力于支持 iOS 17\xe2\x80\x99s 新的快捷方式功能。我有多个应用程序快捷方式,包括一个在选定选项卡中启动应用程序的快捷方式。选项卡选择是通过AppView符合AppEnum协议的自定义枚举完成的。

\n

问题是,由于某种原因,在视图 XYZ 中打开操作无法在 Spotlight 中正确显示\xe2\x80\x99。正如您在下面的屏幕截图中看到的,它没有任何图标或标题。此外,在“快捷方式”应用程序本身中,仅显示第一个短语产生的操作。基于短语的操作AppView仅显示为下面的旧应用程序快捷方式。

\n

知道如何解决这个问题吗?

\n

应用程序快捷方式定义

\n
struct 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)\n

AppView应用枚举

\n
extension AppView: AppEnum {\n    static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "View")\n    \n    static var caseDisplayRepresentations: [Self …
Run Code Online (Sandbox Code Playgroud)

ios swift sirishortcuts appintents ios17

6
推荐指数
1
解决办法
559
查看次数

导入 UIKit 并使用图像作为 AppEnum 的 caseDisplayRepresentations 时出现 AppIntents 问题

I\xe2\x80\x99m 创建一个简单的 AppIntents 快捷方式,需要 UIKit 在我的应用程序中打开 URL。不过,一旦我将 添加import UIKit到我的文件中,Xcode 就会在 处显示以下警告caseDisplayRepresentations,因为我使用图像来显示表示。无需导入 UIKit(或无需 DisplayRepresentations 的图像),一切正常!有什么想法如何解决这个问题吗?

\n
\n

期望直接调用Image初始化程序,但得到Swift.Optional<AppIntents.DisplayRepresentation.Image>

\n
\n

Xcode 警告屏幕截图

\n

代码

\n
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)

ios swift sirishortcuts appintents

3
推荐指数
1
解决办法
172
查看次数