我正在尝试使用新引入的TextEditor. 我的想法是,我在顶部有一些内容(蓝框),然后是 aScrollView和 a以及下面的TextEditor可变数量的内容Text(红框)。
(黄色框)视图TextEditor应该具有最小高度,但如果 \xe2\x80\x93 后面没有太多视图,则应该占据所有可用空间,Text而目前它不这样做...
import SwiftUI\n\nstruct ScrollViewWithTextEditor: View {\n \n var comments = ["Foo", "Bar", "Buzz"]\n \n var loremIpsum = """\n Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in …Run Code Online (Sandbox Code Playgroud) 我想创建一个 SwiftUI macOS 应用程序来创建自己的数据类型。它应该创建扩展名为 的文件.frogmd,该文件应该是包含以下内容的包
images包含图像的文件夹现在,我可以将我的内容保存到磁盘中包含上述结构的文件夹中,但它不会创建具有我所需扩展名的文件,代表包含内容的包。
Exported Type Identifiers我有根据的猜测是我在我的部分中做错了一些事情Info.plist,所以这是我的 plist 的一部分:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>Frog's MD Document</string>
<key>UTTypeIcons</key>
<dict/>
<key>UTTypeIdentifier</key>
<string>ch.appfros.frogmd</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>frogmd</string>
</array>
</dict>
</dict>
</array>
Run Code Online (Sandbox Code Playgroud)
如果它有帮助,这里是到目前为止应用程序的代码:
@main
struct poc_Markdown2App: App {
var body: some Scene {
DocumentGroup(newDocument: FrogMdDocumentWrapper()) { file in
ContentView(document: file.$document.document)
}
}
}
struct FrogMdDocument: Codable {
var id: UUID
var title: String …Run Code Online (Sandbox Code Playgroud) 我不知道我在这里做错了什么;基本上,我无法在 macOS 应用程序的自定义类型列表中进行选择。我是否缺少一致性?
List1代表我的自定义类型的列表,在其中我无法选择条目,而在 中List2,我只使用 Int,它可以工作。
以下是我的观点:
struct ContentView: View {
var body: some View {
VStack {
ListView1()
Divider()
ListView2()
}
}
}
struct ListView1: View {
@State private var selection: Item? = nil
var localSyslogEntries = [
Item(message: "message 1"),
Item(message: "message 2"),
Item(message: "message 3"),
]
var body: some View {
List(localSyslogEntries, selection: $selection) { entry in
VStack {
Text(entry.id.uuidString)
Divider()
}
}
.frame(minHeight: 200.0)
}
}
struct ListView2: View {
@State private var …Run Code Online (Sandbox Code Playgroud) 我在尝试如何使用时惨遭失败.sheet(item:content:). 我知道这里和其他平台上有很多信息,但我就是无法让它发挥作用......
这是我想要 \xe2\x80\x93 的视图的抽象,我不知道我在这里做错了什么:
\nimport SwiftUI\n\nenum SheetView: String, Identifiable {\n var id: Self { self }\n case sheetA = "Sheet A"\n case sheetB = "Sheet B"\n}\n\nstruct SheetViewTest: View {\n @State private var showSheet: SheetView? = nil\n \n var body: some View {\n Form {\n Button(action: {\n showSheet = .sheetA\n print("Button \\(showSheet?.rawValue) tapped\xe2\x80\xa6")\n }, label: {\n Text(SheetView.sheetA.rawValue)\n })\n Button(action: {\n showSheet = .sheetB\n print("Button \\(showSheet?.rawValue) tapped\xe2\x80\xa6")\n }, label: {\n Text(SheetView.sheetB.rawValue)\n })\n }\n .sheet(item: $showSheet) { sheet …Run Code Online (Sandbox Code Playgroud)