首页 > 解决方案 > SwiftUI - “容器文字中的预期表达式”

问题描述

我是 swift 和 Xcode 的新手,但我想知道我的代码有什么问题?我输入了下面显示的代码,并收到错误消息“容器文字中的预期表达式”。在此先感谢您的帮助。

.background(
   LinearGradient(
      gradient: Gradient(colors: [
          Color("ColourBlueberryLight"), Color("ColourBlueberryDark"),)]),
      startPoint: .top, 
      endPoint: .bottom)
)

标签: swiftswiftui

解决方案


小心放置括号和逗号的位置。这是固定代码:

LinearGradient(
    gradient: Gradient(colors: [
        Color("ColourBlueberryLight"), Color("ColourBlueberryDark") /// you had an extra ) here
    ]),
    startPoint: .top,
    endPoint: .bottom
)

结果:

从上到下的蓝色渐变

推荐阅读