小编Nie*_*els的帖子

iOS 14、Swift UI 2 更改 NavigationLink 内所选列表项的背景颜色

在 a 中选择列表项时,如何更改它的背景颜色NavigationLink

它始终以蓝色突出显示(请参阅附加屏幕)。我试图更改listRowBackgroundColor视图修改器,但没有用。

NavigationView {
    
    List (templateModel.model.items) { item in
        
        NavigationLink(destination: DetailView(selectedCategory: item.name, dismiss: dismiss)
            .environmentObject(OrientationInfo())) {
             Text("Test")
                 .listRowBackground(Color.gray)
        }
        .background(Color.black)
        .buttonStyle(PlainButtonStyle())
        .listRowBackground(Color.gray)
    }    
    .background(Color.black) 
    .listStyle(InsetListStyle())
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

swift swiftui swiftui-list swiftui-navigationlink

5
推荐指数
1
解决办法
757
查看次数

在 iPad 上使用 Swift UI 禁用拆分视图

有没有办法在导航视图中使用 iPad 上的 SwiftUI 禁用 SplitView?

ipad ios swift swiftui

4
推荐指数
1
解决办法
1925
查看次数

Swift PDFKit 更改背景颜色

我想在 Swift 中使用苹果 PDFKit 框架更改 pdf 的背景颜色,但它不起作用。创建一些控件(如文本或图像)然后使用它不是问题,但我想更改文档本身的颜色。有没有人有任何想法或解决方案?

  let renderer = UIGraphicsPDFRenderer(bounds: pageRect, format: format)

  let data = renderer.pdfData { (context) in

    context.beginPage()

    let attributes = [
      NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 12),
      NSAttributedString.Key.backgroundColor : UIColor.green
    ]

    let text = "My pdf"

    text.draw(in: CGRect(x: 0, y: 0, width: 200, height: 20), withAttributes: attributes)

    //?
    UIColor.blue.setFill()
    UIColor.blue.setStroke()
    //?
    context.cgContext.setFillColor(cyan: 1.0, magenta: 1.0, yellow: 0.6, black: 1.0, alpha: 1.0)

  }

  return data
Run Code Online (Sandbox Code Playgroud)

ios swift ios-pdfkit

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

Swift UI 2 DocumentGroup获取导航栏按钮操作

在此输入图像描述

我正在为iOS 14(目前正在开发Beta 版)项目使用新的“ DocumentGroup ”场景,我真的不知道如何检测导航栏中的事件,例如按“<”或返回(参见屏幕) “DocumentGroup”场景的预定义导航栏。对于自定义按钮,这是可能的,并且更改栏的样式(例如灰色)也没什么大不了的。我尝试禁用该按钮,向导航栏添加新按钮等。以下示例是您要在 Xcode 中创建新的基于文档的应用程序时的标准代码:

@main struct DocumentAppApp: App {
@SceneBuilder var body: some Scene {
    
    // Adding of a new document
    DocumentGroup(newDocument: DocumentAppDocuments()) { file in
        ContentView(document: file.$document) // .navigationBarBackButtonHidden(true)
    }
}
Run Code Online (Sandbox Code Playgroud)

}

struct ContentView: View {
@Binding var document: DocumentAppDocuments

var body: some View {
    TextEditor(text: $document.text)
}
Run Code Online (Sandbox Code Playgroud)

}

swiftui ios14 documentgroup

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