如何向图像添加带有cornerRadius
的边框。我收到不赞成使用的警告,说我应该使用圆角矩形,但是我不知道该怎么使用
Beta 4:
Image(uiImage: ...)
.border(Color.black, width: 2, cornerRadius: 10)
最佳答案
SwiftUI 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)
}
结果
关于swift - 在SwiftUI Xcode beta 5中将带有cornerRadius的边框添加到图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57269651/