今天发现一个很鬼畜的东西,我想要给
Text
加一个边框,然后边框是圆形⭕️的,很自然的,我用了border
和cornerRadius
,然后......什么鬼,完全鬼畜的效果!!!
不多说了,上正确而简单的代码:
Text("四")
.frame(width:20, height:20, alignment: .center)
.foregroundColor(.white)
.font(.system(size: 9, weight: .light))
.cornerRadius(10.0)
.overlay(Circle().stroke(Color.white))
.padding(.leading,-10)
关键就是 .overlay(Circle().stroke(Color.white))
2021-03-04补充
正圆 圆角边框:
.overlay(Circle().stroke(Color.white))
自己控制圆角cornerRadius
.overlay(
RoundedRectangle(cornerRadius: 6, style: .continuous)
.stroke(Color(UIColor(hexString: "#10AB90")!), lineWidth: 1)
)
网友评论