SkillAgentSearch skills...

SwiftUI

`SwiftUI` Framework Learning and Usage Guide. πŸš€

Install / Use

/learn @Jinxiansen/SwiftUI
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<img src="images/icon/banner.png"/>

Build Status Swift Xcode Xcode MIT

This article refers to SwiftUI apple example and records the results of the exploration here, I hope to be helpful to you.

For the content described in this article, by default you have some experience based on Swift language development, so it will not describe every detail in detail; if you have doubts about Swift syntax, you can learn Swift Grammar.

When learning and using SwiftUI, if you have any questions, you can join the SwiftUI QQ Group: 18552966 to discuss communication.

δΈ­ζ–‡η‰ˆπŸ‡¨πŸ‡³

Recommended Preview: Windows 11 desktop client implemented using SwiftUI.

<img width="80%" src="images/windows11/launchpad.png"/>

⭐️ Stargazers over time

Stargazers over time

πŸ’» Requirements

  • macOS 10.15
  • Xcode 11.0
  • iOS 13.0

Directory:

Basic View

<span id="Layout_D">Layout</span>

<span id="State_D">State and Data Flow</span>

<span id="Gestures_D">Gestures</span>

<h2 id="Basic View">Basic View</h2> <h4 id="Text">Text</h4>

Text is used to display one or more lines of text content with the same effect as UILabel, but it is even better.

If you want to create Text, just create it with Text("SwiftUI"); With chained syntax, you can also add multiple attributes to the text, such as fonts, colors, shadows, spacing between top left and right, and so on.

Example:


Text("SwiftUI")
    .foregroundColor(.orange)
    .bold()
    .font(.system(.largeTitle))
    .fontWeight(.medium)
    .italic()
    .shadow(color: .black, radius: 1, x: 0, y: 2)

<details close> <summary>View running results</summary> <img width="80%" src="images/example/Text.png"/> </details>

HStack and VStack controls are used to host multiple views, as mentioned later.

πŸ”

<h4 id="TextField"> TextField </h4>

TextField is used to add a normal input box, which is often used as a text input.

Example:


TextField(self.$name, placeholder: self.nameText, onEditingChanged: { changed in
    print("onEditing: \(changed)")
}) {
    print("userName: \(self.name)")
    self.endEditing(true)
}}
.padding(10)
.frame(height: 50)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding(EdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 20))

<details close> <summary>View running results</summary> <img width="80%" src="images/example/Field.png"/> </details>

πŸ”

<h4 id="SecureField"> SecureField </h4>

SecureField is generally used as a password input. It is used in the same way as TextField. The example and the running effect are the same as TextField.

<h4 id="Image"> Image </h4>

The Image control is used to display images, example:


Image("icon")
    .resizable()
    .frame(width: 100,
           height: 100,
           alignment: .center)

<details close> <summary>View running results</summary> <img width="80%" src="images/example/Image.png"/> </details>

πŸ”

<h4 id="WebImage"> WebImage </h4>

webImage is used to download the web image, use the URLSession to download the original Image after successful download; you can also use Kingfisher in the downloadWebImage function .

Example:


var body: some View {
        Image(uiImage: self.uiImage ?? placeholderImage)
            .resizable()
            .onAppear(perform: downloadWebImage)
            .frame(width: 80,
                   height: 80,
                   alignment: .center)
            .onTapGesture {
                print("Tap ")
        }
    }

<details close> <summary>View running results</summary> <img width="80%" src="images/example/WebImage.png"/> </details>

πŸ”

<h4 id="Button"> Button </h4>

Button is used to respond to click events.

Example:


Button(action: {
    print("Tap")
}) {
   Text("I'm a Button")
}

<details close> <summary>View running results</summary> <img width="80%" src="images/example/Button.png"/> </details>

πŸ”

<h4 id="PullDownButton"> PullDownButton </h4>

Waiting for release.

<h4 id="ItemBasedPopUpButton"> ItemBasedPopUpButton </h4>

Waiting for release.

<h4 id="NavigationButton"> NavigationButton </h4>

NavigationButtonPage is used to push to the next navigation page.

Example:


NavigationLink(destination: NavigationButtonPage()) {
            Text("NavigationButton").bold()
                .foregroundColor(.orange)
                .font(.largeTitle)
            }
    .navigationBarTitle(Text("Page"))

<details close> <summary>View running results</summary> <img width="80%" src="images/example/NavigationButton.png"/> </details>

πŸ”

<h4 id="PresentationButton" style='color:red'> PresentationButton is deprecated</h4>

PresentationButton ~~is used to pop up a page.~~ has deprecated, please use NavigationLink

πŸ”

<h4 id="EditButton"> EditButton </h4>

EditButton is used to trigger the editing state, just use the navigationBarItems setting when using it.

Example:


navigationBarItems(trailing: EditButton())

<details close> <summary>View running results</summary> <img width="80%" src="images/example/EditButton.png"/> </details>

πŸ”

<h4 id="PasteButton"> PasteButton </h4>

Waiting for release.

<h4 id="Picker"> Picker </h4>

Picker can customize the selector of the data source.

Example:


Picker(selection: $leftIndex, label: Text("Picker")) {
    ForEach(0..<leftSource.count) {
        Text(self.leftSource[$0]).tag($0)
    }
    }.frame(width: UIScreen.main.bounds.width/2)

<details close> <summary>View running results</summary> <img width="80%" src="images/example/Picker.png"/> </details>

πŸ”

<h4 id="DatePicker"> DatePicker </h4>

DatePicker is used to select the absolute date of the control.

Example:


DatePicker(selection: $server.date, 
in: server.spaceDate, 
displayedComponents: .date, label: {
    Text("")
})

<details close> <summary>View running results</summary> <img width="80%" src="images/example/DatePicker.png"/> </details>

πŸ”

<h4 id="Toggle"> Toggle </h4>

Toggle is used to switch the selected state, for example:


Toggle(isOn: $isOn) {
    Text("State: \(self.isOn == true ? "Open":"open")")
}.padding(20)

<details close> <summary>View running results</summary> <img width="80%" src="images/example/Toggle.png"/> </details>

πŸ”

<h4 id="Slider"> Slider </h4>

Slider A control for selecting values from a finite range of values, example:


Slider(value: $data.rating)

Related Skills

View on GitHub
GitHub Stars5.4k
CategoryEducation
Updated5h ago
Forks534

Languages

Swift

Security Score

100/100

Audited on Mar 23, 2026

No findings