ios - 当我使用 SwiftUI 绘制自定义标签栏时,Spacer 不起作用
问题描述
我在swift ui中做了一些练习我做了一个如图所示的标签栏,我想把它移到屏幕的底部,但是我不能用spacer不起作用,也许它也与我想要的路径有关给角落半径我是新的但situi提前谢谢你的回答
struct ContentView: View {
var body: some View {
VStack {
Spacer()
CustomTabBar()
}
}}
struct CustomTabBar: View {
var body: some View {
ZStack {
Path { path in
path.addRect(CGRect(x: 10, y: 200, width: UIScreen.main.bounds.size.width - 20, height: 80))
}
.cornerRadius(40)
.foregroundColor(.blue)
Path { path in
path.addArc(center: CGPoint(x: UIScreen.main.bounds.size.width / 2, y: 200), radius: 50, startAngle: .degrees(0), endAngle: .degrees(180), clockwise: false)
}.foregroundColor(.white)
}
}}
解决方案
是的你是对的。它与您拥有的 Path 元素有关。我会对纯 SwiftUI ShapesRectangle
和Circle
. 这也简化了圆角半径的工作。
这是我的代码:
struct ContentView: View {
var body: some View {
VStack {
Spacer()
CustomTabBar()
}
}
}
struct CustomTabBar: View {
var body: some View {
ZStack {
Rectangle()
.frame(height: 80)
.foregroundColor(Color.blue)
.cornerRadius(40)
.padding(.horizontal, 10)
Circle()
.frame(width: 100, height: 100)
.foregroundColor(Color.white)
.offset(x: 0, y: -50)
}
}
}
这会产生以下结果:
推荐阅读
- r - 将空格附加到命名列表 r
- sql - Postgres 聚合函数,用于计算风速(矢量幅度)和风向(矢量方向)的矢量平均值
- c# - 几何碰撞检测
- php - 使用 SELECT MYSQL 查询在数据库中搜索逗号分隔值
- java - Java 矩阵初始化
- ruby - 在 ruby 中打开填充表单页面
- javascript - 三个js向右线性移动相机
- powershell - Foreach 使用 if/else 检查文件内容
- r - 将 purrr 和 ggplot 与 group_by 和 nest() 一起使用时获取绘图的标题
- java - 如何使用 java 在 selenium 中单击此按钮