Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 笔划/边框快捷键的特定圆角_Swift_Xcode_User Interface_Swiftui_Cornerradius - Fatal编程技术网

Swift 笔划/边框快捷键的特定圆角

Swift 笔划/边框快捷键的特定圆角,swift,xcode,user-interface,swiftui,cornerradius,Swift,Xcode,User Interface,Swiftui,Cornerradius,我正在从事一个SwiftUI项目,在该项目中,我需要一个视图,使其边框只包含一些圆角(例如,左上角和右上角) 我添加了一个带有笔划的圆角矩形,可以将所有的角都圆角。然而,我只需要一些角是圆的,我想不出一个方法来做到这一点 这是我必须添加RoundedRectangle的代码: .overlay( RoundedRectangle(cornerRadius: 20) .stroke(Color.gray, lineWidth: 1) ) 为了只使特定的角变圆,我查看了下面的

我正在从事一个SwiftUI项目,在该项目中,我需要一个视图,使其边框只包含一些圆角(例如,左上角和右上角)

我添加了一个带有笔划的圆角矩形,可以将所有的角都圆角。然而,我只需要一些角是圆的,我想不出一个方法来做到这一点

这是我必须添加RoundedRectangle的代码:

.overlay(
    RoundedRectangle(cornerRadius: 20)
       .stroke(Color.gray, lineWidth: 1)
)
为了只使特定的角变圆,我查看了下面的Stackoverflow帖子:。但是,我必须去掉圆角矩形(因为它会圆角)。我将不得不使用一个正常的边界代替。但,若有一个正常的边界,当圆角并尝试提供的任何答案时,它会切下一块边界

这就是我理想中希望它看起来的样子(这来自Bootstrap的一个示例-我们正在将网站重建为一个应用程序):


谢谢大家!

这里有一种替代的/更简单的方法来重新创建它。为每行添加白色背景,并在其后面添加一个灰色背景色。在行之间添加间距,使灰色背景色看起来像它们之间的分隔符。然后只需在整个视图中添加一个矩形覆盖,就像您在代码中已经添加的那样

struct CornerView: View {
    var body: some View {
        VStack(spacing: 1) {
            ForEach(0..<5) { index in
                Text("Item \(index)")
                    .frame(maxWidth: .infinity)
                    .frame(height: 55)
                    .background(Color.white)
            }
        }
        .background(Color.gray)
        .overlay(
            RoundedRectangle(cornerRadius: 5)
                .stroke(Color.gray, lineWidth: 1)
        )
        .padding()
    }
}

struct CornerView_Previews: PreviewProvider {
    static var previews: some View {
        CornerView2()
    }
}
struct CornerView:视图{
var body:一些观点{
VStack(间距:1){
ForEach(0。。