gpt4 book ai didi

swift - 在 SwiftUI Xcode beta 5 中向图像添加带有 cornerRadius 的边框

转载 作者:搜寻专家 更新时间:2023-11-01 05:46:11 26 4
gpt4 key购买 nike

如何为图像添加带有 cornerRadius 的边框。我收到弃用警告,说我应该使用 RoundedRectange Shape,但我不知道如何使用它

测试版 4:

Image(uiImage: ...)
.border(Color.black, width: 2, cornerRadius: 10)

最佳答案

swift 用户界面 1.0

使用 cornerRadius 和叠加修饰符

这是另一种方法,我们可以使用 cornerRadius 修饰符(它会剪裁 View ),然后用颜色覆盖笔划。

VStack(spacing: 40) {
Text("Image Border").font(.largeTitle)
Text("Using cornerRadius & overlay").font(.title).foregroundColor(.gray)
Text("Using cornerRadius will also clip the image. Then overlay a border.")
.frame(minWidth: 0, maxWidth: .infinity)
.font(.title)
.padding()
.background(Color.orange)
.foregroundColor(.black)

Image("profile")
.cornerRadius(10)
.overlay(RoundedRectangle(cornerRadius: 10)
.stroke(Color.orange, lineWidth: 4))
.shadow(radius: 10)
}

结果

enter image description here

关于swift - 在 SwiftUI Xcode beta 5 中向图像添加带有 cornerRadius 的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57269651/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com