简体   繁体   中英

How can I change DatePicker font weight in SwiftUI

I've tried below code. But .font function does not change anything. I want to the date more darker. How can I do that?

struct TestView: View {
    @State private var date = Date()
    
    var body: some View {
        HStack {
            DatePicker("", selection: $date, in: ...Date(), displayedComponents: .date)
                .padding()
                .labelsHidden()
                .accentColor(.red)
                .font(Font.body.weight(.bold))
            
            Spacer()
        }
    }
}

While you can't specifically change the text for the DatePicker, you can use and HStack to accomplish the desired outcome.

    HStack {
             Text("End Date")
                   .font(.custom((Fonts.gse), size: 18))
                   .fontWeight(.medium)
             Spacer()
             DatePicker("", selection: self.$endingDate, in: self.dateRange, displayedComponents: [.date, .hourAndMinute])
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM