2

有什么方法可以在 SwiftUI 中更改分段控制器的高度,或者仅通过创建自定义分段控制器来实现?我尝试了 .frame(height) 但没有任何改变。我需要增加分段控制器的高度。

@State private var userType = 0

init() {
    UISegmentedControl.appearance().selectedSegmentTintColor = .white
    UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor: UIColor.blue], for: .selected)
    UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor: UIColor.lightGray], for: .normal)
}

var body: some View {
    VStack {

    HStack {
        Picker("Choose user type", selection: $userType) {
            Text("User")
                .tag(0)
            Text("Administrator")
                .tag(1)
        }
        .pickerStyle(.segmented)
        .frame(height: 40)
        .padding(.horizontal, 16)
        }
}}

在此处输入图像描述

4

0 回答 0