title: How to change text size using picker in swiftui
body: <p>I am a beginner level in swiftui. I begin a bible app as a starter's project. I create a Setting and from that setting, I want to change my font size by using a picker. It's been 4 days that I am searching online for a solution, and I couldn't figure out what should I do.</p>
  <p>Question 1: I don't know how to update the font size based on the picker selection. Some say to use .onChange, but I don't know how to do it. So, I tried using a switch case method, but still don't know how to update the text. Also, I tried using custom modifiers to replace .font(.footnote) something like that. But still, I don't know how to update it and EnvironmentalObject doesn't helpful at all. Please guide me on how to solve the issue.</p>
  <p>Question 2: Every time I play the canvas, the picker selection always starts from the default index which makes sense. But in the actual app, does it always starts with the default index after the user selected a different index or what should I do in order to keep the preselected index.</p>
  <p>Here is my code:</p>
  <pre><code>import SwiftUI
  
  struct Setting: View {
      @State private var fontSizeIndex = 3
      @State private var fontIndex = 1
  
  
     var body: some View {
          NavigationView {
              ScrollView {
  
                 // Text Settings
                  Form {
                      
                      // Font Size Picker
                      Section(header: Text(&quot;Text Settings&quot;)) {
  
                           Picker(selection: $fontSizeIndex, label: Text(&quot;Font Size&quot;), 
                              content: {
                              Text(&quot;Extra Small&quot;).tag(1)
                              Text(&quot;Small&quot;).tag(2)
                              Text(&quot;Medium&quot;).tag(3)
                              Text(&quot;Large&quot;).tag(4)
                              Text(&quot;Extra Large&quot;).tag(5)
                           })
  
  
                          // Font Picker
                          // I plan to make custom fonts if I know how to update my 
                          // selection
                          Picker(selection: $fontIndex, label: Text(&quot;Font&quot;), content: {
                              Text(&quot;Font1&quot;).tag(1)
                              Text(&quot;Font2&quot;).tag(2)
                              Text(&quot;Font3&quot;).tag(3)
                              Text(&quot;Font4&quot;).tag(4)
                              Text(&quot;Font5&quot;).tag(5)
                              Text(&quot;Font6&quot;).tag(6)
                              Text(&quot;Font7&quot;).tag(7)
                          })
  
                      }
                  }
                  .frame(height:280)
              }
        }
  }
  </code></pre>
  <p>This is my Text or Scripture() which is in another view</p>
  <pre><code>import SwiftUI
  
  struct Scripture: View {
  
      //@EnvironmentObject var fsc: FontSizeChanging
      
      var body: some View {
          ScrollView {
          
              Text(&quot;Hih in Zeisu Khazih khang ciamtehna ahi hi. Amah in David tapa hi a, David in Abraham tapa ahi hi. 2 Abraham tapa Isaac, Isaac tapa Jacob, Jacob tapa Judah le a sanggam pasal teng ahi hi. 3 Judah in a zi Tamar tawh a neih a tapa Perez le Zerah, Perez tapa Hezron, Hezron tapa Ram, 4 Ram tapa Amminadab, Amminadab tapa Nahshon, Nahshon tapa Salmon, 5 Salmon in a zi Rahab tawh a neih a tapa Boaz, Boaz in a zi Ruth tawh a neih a tapa Obed, Obed tapa Jesse, 6 Jesse tapa kumpipa David ahi hi. David in Uriah zi tawh a neih a tapa Solomon, 7 Solomon tapa Rehoboam, Rehoboam tapa Abijah, Abijah tapa Asa, 8 Asa tapa Jehoshaphat, Jehoshaphat tapa Joram, Joram tapa Uzziah, 9 Uzziah tapa Jotham, Jotham tapa Ahaz, Ahaz tapa Hezekiah, 10 Hezekiah tapa Manasseh, Manasseh tapa Amon, Amon tapa Josiah ahi hi. 11 Jeconiah le a sanggam pasal tengin Babylon gamah sala a kipaipih madeuh in a suak Josiah tate ahi uh hi. 12 Babylon gama saltan khit ciangin Jeconiah in a neih a tapa Shealtiel, Shealtiel tapa Zerubbabel, 13 Zerubbabel tapa Abiud, Abiud tapa Eliakim, Eliakim tapa Azor, 14 Azor tapa Zadok, Zadok tapa Achim, Achim tapa Eliud, 15 Eliud tapa Eleazar, Eleazar tapa Matthan, Matthan tapa Jacob, 16 Jacob tapa Joseph hi a, Joseph in Khazih a kici Zeisu a hong suahna Mary pasal ahi hi. 17 Tua hi a, Abraham khang panin David khang ciang a vekin khang sawm le khang li, David khang panin Babylon gama saltang dinga a kimat hun ciang khang sawm le khang li, Babylon gama saltan hun pan Khazih khang ciang khang sawm le khang li mah ahi hi. 18 Zeisu Khazih a suahzia hih bang ahi hi. A nu Mary pen Joseph zi dingin zuthawl kipiasa hi a, a kiteenma un Kha Siangtho hangin gai hi ci in kithei hi. 19 A lawmpa Joseph in mi lungsim hoih hi a, a lawmnu Mary min daisak nuamlo ahih manin maksim dingin a ngaihsun hi.&quot;)
                  //.font(fsc.fontSize)
                  .foregroundColor(.primary)
                  //.font(Setting(fontSizeIndex: self.$fontSizeIndex))
                  .multilineTextAlignment(.leading) // test .center here
                  .lineSpacing(5)
                  .padding()
                  
          }
      }
  }
  
  struct Scripture_Previews: PreviewProvider {
      static var previews: some View {
          Scripture()
      }
  }
  </code></pre>