Posts

Showing posts from March, 2020

SwiftUI - Form

Image
Many a times we need to design a User Interface where we need to take users inputs in TextFields, Date Pickers, Pickers, Toggles. As of now what we followed is we either used a ScrollView for a fixed set of inputs or TableView for list of inputs. SwiftUI provides us with a simple solution called Form for this. Form is a container or a collection of user input controls. Forms can contain Sections which can group input controls. Also keep that in mind that forms are scrollable, we don't need to worry about what will happen if we add multiple items and it gets out of the screen. Lets see following example: struct ContentView : View {     @ State private var name = ""     @ State private var age = ""     var body : some View {         Form {             Text ( "Personal Details Form" )                 . font (. headline )                 . foregroundColor (. red )             TextField ( "Name" , text: $name

SwiftUI UIControls

Image
Let's see what UIControls we have to design UI in SwiftUI. UIKit                            SwiftUI UIViewController View UITableViewController List UINavigationViewController NavigationView UITabViewController TabView UIAlertViewController Alert UILabel         Text UITextField TextField UIStackView 1. VStack 2. HStack 3. ZStack UIScrollView ScrollView UIImageView Image UIPickerView Picker UIButton         Button UIDatePicker DatePicker UISlider         Slider UIStepper Stepper UISwitch         Toggle I know this is not a complete list; I am too exploring it. ContentView.swift is the file where we are going to code. By default we get a Text as Hello, World! Let's see what this file actually means and what it does. So here we have two structures:  ContentView struct - This is the place to code or design.  ContentView_Preview

Intro to SwiftUI

Image
As we all know SwiftUI is here and it has completely changed development of apps, not only the UI but the way we code. Basic Requirement For Development and Deployment: Xcode 11 or above iOS 13 or above Here I have created a new project selecting SwiftUI as User Interface. As we can see now the Left Pane consists of some new files like: 1. SceneDelegate.swift 2. ContentView.swift On exploring AppDelegate.swift you will notice it has some methods we are not been aware of in the past like  func application ( _ application: UIApplication , configurationForConnecting connectingSceneSession: UISceneSession , options: UIScene . ConnectionOptions ) -> UISceneConfiguration func application ( _ application: UIApplication , didDiscardSceneSessions sceneSessions: Set < UISceneSession >)   Heading towards the SceneDelegate.swift, this file is the place where we are connecting our scenes to the main window. ContentView.swift has our scene