我正在尝试在 RoundedRectangle 周围创建一个边框,其中边框的圆角半径为 25。这是我的代码。
RoundedRectangle(cornerRadius: 25)
.fill(Color.white)
.frame(width: 290, height: 315)
.border(Color("Dark Text"), width: 3)
.cornerRadius(25)
Run Code Online (Sandbox Code Playgroud)
从这段代码中,矩形的角半径为 25,但边框与框架匹配。我怎样才能让边框的cornerRadius为25?
这应该做:
RoundedRectangle(cornerRadius: 25)
.stroke(Color.black, lineWidth: 5) // used for border
.frame(width: 290, height: 315)
Run Code Online (Sandbox Code Playgroud)
如果您想使用多个修饰符,有时它不会让您使用笔划。例如与fill. 在这种情况下使用overlay这样的:
RoundedRectangle(cornerRadius: 25)
.fill(Color.white)
.frame(width: 290, height: 315)
.overlay(
RoundedRectangle(cornerRadius: 25)
.stroke(Color.black, lineWidth: 5)
)
Run Code Online (Sandbox Code Playgroud)