swift - 在 SwiftUI Xcode beta 5 中为图像添加带有cornerRadius 的边框
问题描述
如何cornerRadius
向图像添加带有 a 的边框。我收到一条弃用警告,说我应该使用 RoundedRectange 形状,但我不知道如何准确地使用它
测试版 4:
Image(uiImage: ...)
.border(Color.black, width: 2, cornerRadius: 10)
解决方案
SwiftUI 1.0
使用cornerRadius 和覆盖修改器
这是另一种我们可以使用cornerRadius修改器(它剪切视图)然后用颜色覆盖笔划的方法。
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)
}
结果
推荐阅读
- javascript - 如何选择()元素背景颜色?
- c# - 如何将数字从十进制传送到整个字节数组
- bash - 如何重新运行脚本?
- angular - ViewEncapsulation.ShadowDom 与 ViewEncapsulation.Native
- javascript - i 在 JavaScript for 循环中不递增
- python - 如何序列化包含原始 JSON 的模型字段?
- javascript - 单击按钮将数组值加载到变量中
- android - 使用底部导航栏从片段开始活动
- python - BeautifulSoup 在给定类的 div 中获取所有不同的属性值
- java - 为什么 URI 构造函数在其 URI 参数中允许非百分比编码的保留特殊字符(正斜杠)?