我正在从this GitHub repo对Xcode项目进行一些更改。我试图改变选择菜单的分段风格,但我无法让它工作。我想改变的选择器部分在下面。有人能帮帮我吗?
import SwiftUI
import VanMoofKit
// MARK: - SpeedLimitCard
extension BikeView {
/// The SpeedLimitCard
struct SpeedLimitCard {
@EnvironmentObject
private var bike: VanMoof.Bike
}
}
// MARK: - View
extension BikeView.SpeedLimitCard: View {
/// The content and behavior of the view.
var body: some View {
BikeView.Card(
placeholderValue: .europe,
title: "Speed Limit",
systemImage: "speedometer",
provider: {
try await self.bike.speedLimit
},
publisher: self.bike.speedLimitPublisher,
content: { speedLimit in
Gauge(
value: speedLimit.measurement.value,
in: 0...37
) {
Text(verbatim: speedLimit.measurement.unit.symbol)
} currentValueLabel: {
Text(verbatim: .init(Int(speedLimit.measurement.value)))
}
.scaleEffect(1.4)
.gaugeStyle(.accessoryCircular)
.tint(.teal)
.pickerStyle(SegmentedPickerStyle())
},
actions: { currentSpeedLimit in
ForEach(VanMoof.Bike.SpeedLimit.allCases, id: \.self) { speedLimit in
Button {
Task {
try await self.bike.set(speedLimit: speedLimit)
}
} label: {
Label {
Text(
verbatim: "\(speedLimit.localizedString) (\(speedLimit.measurement.formatted()))"
)
} icon: {
if currentSpeedLimit == speedLimit {
Image(systemName: "checkmark")
}
}
}
}
}
)
}
}
private extension VanMoof.Bike.SpeedLimit {
var localizedString: String {
switch self {
case .europe:
return "Europe"
case .unitedStates:
return "United States"
case .japan:
return "Japan"
}
}
}
添加.pickerStyle(SegmentedPickerStyle())
,我希望它更改为分段pickerstyle
1条答案
按热度按时间l3zydbqr1#
在你提供的代码中没有
Picker
,所以设置.pickerStyle
可能不会有任何效果。除非这是你正在使用的第三方库(我不熟悉)支持的东西。下面是一个独立的例子,说明如何使用之前使用的选项来形成分段选择器:
您可以尝试将此
Picker
插入到代码中,以替换使用参数actions
传递到BikeView.Card
的ForEach
。祝你好运!