ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

SwiftUI Framework

Home / Article & Blogs / Mobility / SwiftUI Framework
By pravallikadamerla inMobility

Swift UI is an expressive UI framework for  macOS, tvOS, iOS, watchOS, iPadOS that allows you to design and develop user interfaces with way less code and in a “Declarative way”

SwiftUI lets you ignore Interface Builder (IB) and storyboards without having to write detailed step-by-step instructions for laying out your UI

 

Getting Started

Lets start from scratch

1. We need Xcode To Start the process (If you have it continue with step 2
else Install ‘XCode’ from the App Store )
2. Create a new XCode project,
3. Under iOS select single View App,
4. Make sure at the  bottom Swift UI option  is checked, else it ill generate storyboard file

 

5. Now XCode will generate a file called contentView.swift  and the old App delegate.swift is now split into
AppDelegate.swift and
SceneDelegate.swift
SceneDelegate is not specific to SwiftUI but this line is:

 

window.rootViewController = UIHostingController(rootView: ContentView())

 

SwiftUI is declarative: You declare how you want the UI to look, and SwiftUI converts your declarations into efficient code that gets the job done

You won’t be writing hundreds of lines of code to create views

 

6. //Basic go through of the code
Import Swift UI
Struct ContentView: View{
Var body : some view {
Text(“Hello SwiftUI”)
}
#IF DEBUG
Struct ContentView_Preview :PreviewProvider {
Static var previews : someview{
ContentView()
}
}
#endIf

7. The tags #If DEBUG, #endIf  are the directives which run only in debug mode by default

 And when you are ready with the package for deployment to upload to the Appstore it is gonna go from debug to production mode so it is not going to run

These are used to control what you want to see in the preview

 

 

Import Swift UI
Struct ContentView: View{
Var body : some view {
Text(“Hello SwiftU”).font(.title).foregroundColor(.green)
}
#IF DEBUG
Struct ContentView_Preview :PreviewProvider {
Static var previews : someview{
ContentView()
}
}
#endIf

 

 

1.If we want to have Vertical views we have the concept called VStack
2.If we want to have Horizontal views we have the concept called HStack
3.Reflecting Font, FontStyles, FontColors to the Text is uncomplicated by appending a method successive to Text

 

Import Swift UI
Struct ContentView: View{
Var body : some view {
VStack{
Text(“Turtle Rock”).font(.title).color(.green)
Text(“Joshua Tree National Park”).font(.subheadline)
}
}
}
#IF DEBUG
Struct ContentView_Preview :PreviewProvider {
Static var previews : someview{
ContentView()
}
}
#endIf

Text Views

 

Import Swift UI
Struct ContentView: View{
Var body : some view {
VStack(alignment :.leading)
{
Text(“Turtle Rock”).font(.title).color(.green)
HStack{
Text(“Joshua Tree National Park”).font(.subheadline)
Text(“California”).font(.subheadline)
}
}.padding()
}
}
#IF DEBUG
Struct ContentView_Preview :PreviewProvider {
Static var previews : someview{
ContentView()
}
}
#endIf

ImageView

import SwiftUI
struct CircleImage: View {
var body: some View { Image(“SwiftUI”).clipShape(Circle()).overlay(Circle().stroke(Color.white,lineWidth: 2)).shadow(radius: 10)
}
}

#if DEBUG
struct CircleImage_Previews: PreviewProvider {
static var previews: some View {
CircleImage()
}
}
#endif

MapView

Create another controller for map view

import SwiftUI
import MapKit
struct MapView: UIViewRepresentable {
func makeUIView(context:UIViewRepresentableContext) -> MKMapView{
MKMapView()
}
func updateUIView(_ uiview :MKMapView, context :UIViewRepresentableContext)
{
let coordinate = CLLocationCoordinate2D(latitude:34.011286 ,longitude :-116.166868)
let span = MKCoordinateSpan(latitudeDelta :2.0,longitudeDelta :2.0)
let region = MKCoordinateRegion(center :coordinate ,span:span)
uiview.setRegion(region , animated:true)
}
}

#if DEBUG
Struct MapView_Previews: PreviewProvider {
static var previews: some View {
MapView()
}
}
#endif

ContentView

 

import SwiftUI
struct ContentView: View {
var body: some View {
VStack{
MapView().frame( height:CGFloat(300)).edgesIgnoringSafeArea(.top)
CircleImage()
.offset( y: CGFloat(-130)).padding(.bottom, CGFloat(-130))
VStack()
{
Text(“Turtle Rock”).font(.title)
HStack{
Text(“Joshua Tree National Park”).font(.subheadline)
Text(“California”).font(.subheadline)
}
}.padding()
}
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif

Output:

 

Prerequisites:

Swift 5, iOS 13, XCode 11

References:

https://www.hackingwithswift.com/quick-start/swiftui/how-to-create-static-labels-with-a-text-view

https://www.raywenderlich.com/3715234-swiftui-getting-started

UP NEXT :

MIGRATION OF UI TO SWIFTUI

 

IOSSwiftUIXcode
87
Like this post
4 Posts
pravallikadamerla

Search Posts

Archives

Categories

Recent posts

Meet OmniStudio – Revolutionize Your Creative Work

Meet OmniStudio – Revolutionize Your Creative Work

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

  • Previous PostUtilization of Hierarchy custom settings in formula field, custom button, process builder or workflow rules without hard-coding
  • Next PostPicture inside Picture (PiP)

Related Posts

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT