Code Monkey home page Code Monkey logo

swituitutorials's Introduction

Apple SwiftUI Tutorials: https://developer.apple.com/tutorials/swiftui/

Creating and combining Views

  1. By default, SwiftUI view files declare two struct, the first struct conforms to the View protocol and describes the view's content and layout. The second struct declares a preview for that view.
  2. spacer expands to make its containing view use all of the space of its parent view, instead of having its size defined only by its contents.
  3. padding() modifier method
  4. You can use a stack to return multiple views from a body property.
  5. A modifier returns a view that applies a new behavior or visual change. You can chain multiple modifier to achieve the effects you need.
Text("Hello world!")
    .font(.title)
    .foregroundColor(.purple)

Building Lists and Navigation

  1. Use the previewLayout(_ :) modifer to set a size that approximates a row in a list
struct LandmarkRow_Previews: PreviewProvider {
    static var previews: some View {
        LandmarkRow(landmark: landmarkData[1])
            .previewLayout(.fixed(width: 300, height: 70))
    }
}
  1. To preivew in multiple devices, using:
struct LandmarkList_Previews: PreviewProvider {
    static var previews: some View {
        ForEach(["iPhone SE", "iPhone XS Max"], id: \.self) { deviceName in
            LandmarkList()
                .previewDevice(PreviewDevice(rawValue: deviceName))
                .previewDisplayName(deviceName)
        }
    }
}

Handing User Input

  1. state is a value, or a set of values, that can change over time, and that affects a view's behavior, content, or layout. You use a property with the @state attribute to add state to a view.
struct LandmarkList: View {
    @State var showFavoritesOnly = false
    // ...snip
}
  1. You use $ prefix to access a binding to a state variable, or one of its properties.
Toogle(isOn: $showFavoritesOnly) {
    Text("Favorites only")
}
  1. Observable obejct is a custom object for your data that can be cound to a view from storage in SwiftUI's environment. SwiftUI subscribes to your observable object, and updates any views that need refreshing when the data changes.

Drawing Paths and Shapes

swituitutorials's People

Contributors

ziyochiro avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.