我创建了一个自定义 UIView 作为 .xib 文件,其中 UIView 有一个按钮。我使用以下代码加载 UIView。
struct ContentView: View {
var body: some View {
CustomViewRepresentable()
}
}
struct CustomViewRepresentable: UIViewRepresentable {
typealias UIViewType = CustomView
func makeUIView(context: UIViewRepresentableContext<CustomViewRepresentable>) -> CustomView {
let customView = Bundle.main.loadNibNamed("CustomView", owner: nil, options: nil)![0] as! CustomView
return customView
}
func updateUIView(_ uiView: CustomView, context: UIViewRepresentableContext<CustomViewRepresentable>) {
}
}
Run Code Online (Sandbox Code Playgroud)
自定义视图具有以下代码:
class CustomView: UIView {
@IBOutlet weak var button: UIButton!
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个带有侧边栏和拆分视图的三列窗口。拆分视图中的每个左右视图都应该有一个相应的 ToolbarItem,显示在它们各自的工具栏/导航标题空间中。
为此,我创建了一个简单的视图,它有一个侧边栏、左视图和右视图。我为左视图创建了一个 ToolbarItem,为右视图创建了另一个 ToolbarItem。但是,属于右视图的 ToolbarItem 显示在左视图的工具栏空间中。有没有办法创建特定于每个视图的 ToolbarItem。任何帮助是极大的赞赏。
下面是我创建的源代码。我还附上了显示问题的屏幕截图。我使用的是 Xcode 12 beta 和 macOS Big Sur Beta。
import SwiftUI
struct ContentView: View {
enum NavigationItem {
case demo
}
@State private var selection: Set<NavigationItem> = [.demo]
var body: some View {
NavigationView {
List(selection: $selection) {
Label("Demo", systemImage: "list.bullet")
}
.listStyle(SidebarListStyle())
.frame(minWidth: 200, idealWidth: 250, maxWidth: 300, maxHeight: .infinity)
Text("Left")
.frame(maxWidth: 500, maxHeight: .infinity)
.toolbar {
ToolbarItem {
Button(action: {}) {
Text("Left Toolbar")
}
}
ToolbarItem { Spacer() }
} …Run Code Online (Sandbox Code Playgroud) 我正在两个 UITableView 之间实现拖放。在 tableView 上拖动项目时,tableView 会自动显示将插入新单元格的空间。我想通过更改背景颜色来突出显示该空间。
目前,新单元格的空间显示为白色。如果我改变了 UITableView 的背景色,那么空间就反映了相应的背景色。但是,我不想更改 tableView 的背景颜色。
有人可以帮助我如何实现它吗?
这是我正在寻找的功能的屏幕截图。
谢谢,菲利克斯.J