如何在SwiftUI中使用SegmentedPickerStyle()更改选取器的高度?

问题描述 投票:8回答:1

如何在SwiftUI中更改选择器框架?

Picker(selection: .constant(1), label: Text("Picker")) {
    Text("Hello").tag(1)
    Text("World").tag(2)
}
.frame(height: 60)
.pickerStyle(SegmentedPickerStyle())

我们期望拾取器高度等于60,但不相等。

ios swift swiftui
1个回答
0
投票

没有直接的方法可以更改SegmentedPickerStyle拾取器的高度,但是我们可以使用以下代码对其进行缩放。

Picker(selection: .constant(1), label: Text("Picker")) {
    Text("Hello").tag(1)
    Text("World").tag(2)
}
.frame(height: 60)
.pickerStyle(SegmentedPickerStyle())
.scaledToFit()
.scaleEffect(CGSize(width: 1.5, height: 1.5))
© www.soinside.com 2019 - 2024. All rights reserved.