Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bold text in SwiftUI TextField?

There is no built-in font-weight modifier for textfield in SwiftUI, as of Xcode 11.2.1.

How can we introduce font-weight without extending UITextField as UIViewRepresentable?

like image 798
Abhishek Biswas Avatar asked Dec 03 '19 04:12

Abhishek Biswas


People also ask

How do I change the font in SwiftUI?

Hold the command key and click the text to bring up a pop-over menu. Choose Show SwiftUI Inspector and then you can edit the text/font properties.

What fonts are available in SwiftUI?

SwiftUI lets you customize Text by applying a . font() modifier. The default iOS font is called San Francisco and if you don't explicitly change it, then all of your text will have the default iOS look. Some other options of standard fonts include: title, headline, subheadline, body, callout, caption or footnote.


2 Answers

A general approach for using standard font size options and weights that work with SwiftUI TextField. For example:

TextField("Name", text: $name)   .font(Font.headline.weight(.light)) 

Available standard size options (smallest to largest):

.caption .footnote .subheadline .callout .body .headline .title3 .title2 .title .largeTitle 

Available standard font weights (lightest to heaviest):

.ultralight .thin .light .regular .medium .semibold .bold .heavy .black 
like image 123
Cary Champlin Avatar answered Sep 24 '22 17:09

Cary Champlin


import SwiftUI  struct ContentView: View {     @State var TextValue: String = "Hello"      var body: some View {         VStack {             TextField("placeholder", text: $TextValue)             .padding(.horizontal, 50)                 .font(.system(size: 30, weight: .heavy, design: .default))         }     } }  struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } } 

enter image description here

like image 36
Ramprasath Selvam Avatar answered Sep 21 '22 17:09

Ramprasath Selvam