Giter VIP home page Giter VIP logo

design-your-app's Introduction

Design your App

Main task: This practice is from Apple's learning center Design your App.

And using SwiftUI to build a completely project.

ContentView:

Show different result by tapping each buttons.

I created three different buttons(Thankful, Excited, Joyful) to switching between different text contents.

By tapping each button, the text content will display a different result.

VStack {
    HStack {
        
        // Joyful Button
        Button(action: {
            print("Showing Thankful Content")
            
            textContent = infomation[0].content
            
        }) {
            Text("Thankful")
                .font(.largeTitle)
                .fontWeight(.semibold)
                .foregroundColor(.white)
                .frame(width: 300, height: 180)
                .background(
                    LinearGradient(
                        gradient: .init(colors: [Color.white, Color.blue.opacity(0.7)]),
                        startPoint: .init(x: -0.33, y: -0.33),
                        endPoint: .init(x: 0.66, y: 0.66)
                    ))
                .cornerRadius(20)
                .overlay(
                    RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.gray.opacity(0.3), lineWidth: 2)
                )
        }
        .padding(40)
        
        // Joyful Button
        Button (action: {
            print("Showing Thankful Content")
            
            textContent = infomation[1].content
            
        }) {
            Text("Joyful")
                .font(.largeTitle)
                .fontWeight(.semibold)
                .foregroundStyle(.white)
                .backgroundStyle(.gray)
                .frame(width: 300, height: 180)
                .background(
                    LinearGradient(
                        gradient: .init(colors: [Color.white, Color.blue.opacity(0.7)]),
                        startPoint: .init(x: -0.33, y: -0.33),
                        endPoint: .init(x: 0.66, y: 0.66)
                    ))
                .cornerRadius(20)
                .overlay(
                    RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.gray.opacity(0.3), lineWidth: 2)
                )
        }
        .padding(40)
        
        // Excited Button
        Button(action: {
            print("Showing Excited Content")
            
            textContent = infomation[2].content
        
            
        }) {
            Text("Excited")
                .font(.largeTitle)
                .fontWeight(.semibold)
                .foregroundStyle(.white)
                .controlSize(.large)
                .frame(width: 300, height: 180)
                .background(
                    LinearGradient(
                        gradient: .init(colors: [Color.white, Color.blue.opacity(0.7)]),
                        startPoint: .init(x: -0.33, y: -0.33),
                        endPoint: .init(x: 0.66, y: 0.66)
                    ))
                .cornerRadius(20)
                .overlay(
                    RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.gray.opacity(0.3), lineWidth: 2)
                )
        }
        .padding(40)
    }

Shows the gardientColor in background by using ZStack.

        // Add Angular Gradient effect
        ZStack {
            AngularGradient(
                colors: [
                    .red,
                    .teal,
                    .blue,
                    .black,
                    .indigo,
                    .red
                ],
                center: .center
            )
            
            // 變滿版
            .edgesIgnoringSafeArea(.all)

Show content after the tapping different buttons

                // Add ZStack in this view.
                ZStack {
                    Text(textContent)
                        .font(.largeTitle).bold()
                        .fontWeight(.semibold)
                        .frame(width: 1070, height: 300)
                        .background(
                            LinearGradient(
                                gradient: .init(colors: [Color.white.opacity(0.8), Color.blue.opacity(0.7)]),
                            startPoint: .init(x: -0.33, y: -0.33),
                            endPoint: .init(x: 0.66, y: 0.66)
                        ))
                        .cornerRadius(20)
                }

Data.swift:

Create the information data array for switch different content.

import Foundation
import SwiftUI

struct Info {
    let content: String
}

let infomation: [Info] = [
    Info(content: "I am thankful for the support of my family and friends."),
    Info(content: "Feeling excited about the new opportunities ahead."),
    Info(content: "Joyful moments are often found in the simplest things."),
    Info(content: "Grateful for the kindness of strangers."),
    Info(content: "Excited to start a new chapter in my life.")
]

Reference

design-your-app's People

Contributors

dwhao84 avatar

Watchers

 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.