我想要文本字段的底部边框作为以下设计

enter image description here

我的代码

    ZStack {
    RoundedRectangle(cornerRadius: 6)
    .fill(LinearGradient(colors: [Color("#B37CFA").opacity(0.5),Color("#2A5389").opacity(0.5),Color("#2DB854").opacity(0.5)], startPoint: .leading, endPoint: .trailing))
    .frame(height: 50)
    .mask(
        Rectangle()
        .frame(height: 20)
        .cornerRadius(10, corners: [.bottomLeft, .bottomRight])
         )
        }

Outputenter image description here

推荐答案

使用blendModecompositingGroup修改器:

ZStack {
    RoundedRectangle(cornerRadius: 10)
        .fill(
            LinearGradient(
                colors: [.red, .green,.blue],
                startPoint: .leading,
                endPoint: .trailing
            )
        )

    RoundedRectangle(cornerRadius: 10)
        .offset(y: -4)
        .blendMode(.destinationOut)
}
.frame(height: 50)
.compositingGroup()

Demo

Ios相关问答推荐

Firebase SDK 10+—无法安装软件包

带外部笔划的圆形进度视图

带有动画层的UIView表示不会在工作表中设置动画

如何在本地iOS没有插件的情况下处理平台线程?

SwiftUI Divider过大了其父视图

圆角矩形路径上的蛇形动画

iOS 16 中的状态栏 colored颜色

如何以编程方式触发 SwiftUI DatePicker?

CGPath intersection(_:using:) 和朋友(iOS 16 中的新功能)坏了?

iOS 16 堆栈视图中按钮的奇怪动画

expo EAS build (iOS) 在 Pod 安装步骤中失败 (SDK45 & 46)

VStack 显示错误实例方法 'sheet(item:onDismiss:content:)' 要求 'Int' 符合 'Identifiable'

来自 c++ 的runtime_error未在 iOS 中捕获

iOS 8 - 使用自定义演示关闭视图控制器后屏幕空白

使用未知类型创建图像格式是一个错误与 UIImagePickerController

try 在 iOS 中处理后退导航按钮操作

SwiftUI NavigationView navigationBarTitle LayoutConstraints 问题

使用 Chrome DevTools 调试 iOS 6+7 Mobile Safari

在 UITableViewController 中使用 UISearchDisplayController 时断言失败

UITableView 中的圆形 UIImageView 没有性能影响?