๐Ÿ“ฑ App Development Study/iOS๐ŸŽ

[Udemy iOS & Swift Bootcamp] Complex Designs and Layouts using SwiftUI

ibelieveinme 2023. 7. 7. 18:24
728x90

SwiftUI๋กœ ์ข€ ๋” ๋ณต์žกํ•œ ๋””์ž์ธ์€ ์–ด๋–ป๊ฒŒ ๋งŒ๋“ค๊นŒ?

 

1. background color ์ง€์ •ํ•˜๊ธฐ

import SwiftUI

struct ContentView: View {
    var body: some View {
        
        ZStack {
            Color(red: 1.00, green: 0.69, blue: 0.25)
                .edgesIgnoringSafeArea(.all)
            Text("Hello, world!")
                .padding()

        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
        
    }
}

Zstack ์œผ๋กœ ์Œ“๋„๋ก ํ•ด์ฃผ๊ณ , ๋งจ ๋ฐ‘์— Color๋ฅผ ๊น”์•„์ค€๋‹ค. Xcode ์—์„œ ์ œ๊ณตํ•˜๋Š” ์ƒ‰์ด ๋ง˜์— ์•ˆ๋“ค๋ฉด Custom ์ปฌ๋Ÿฌ๋ฅผ ์ฐพ์•„๋ณด์ž.

.edgesIgnoringSafeArea(.all) ์„ ์ ์–ด์ฃผ๋ฉด safe area ์˜์—ญ๊นŒ์ง€ ์ƒ‰๊น”์„ ์ž…ํž ์ˆ˜ ์žˆ๋‹ค.

 

[์ปฌ๋Ÿฌ ์ฐพ๋Š” ๊ณณ]

https://flatuicolors.com/

 

Flat UI Colors 2 - 14 Color Palettes, 280 colors ๐ŸŽจ

280 handpicked colors ready for COPY & PASTE

flatuicolors.com

 

[16์ง„์ˆ˜ -> UIColor๋กœ ๋ฐ”๊พธ๊ธฐ]

https://www.uicolor.io/#/hex-to-ui

 

Convert HEX & RGB colors to UIColor

UIColor.io is a website that helps you convert HEX & RGB colors to UIColor for Objective-C, Swift and Xamarin featuring a colorpicker and copy to clipboard functionality to make things easier.

www.uicolor.io

 

2. ๊ธ€์ž ๊พธ๋ฏธ๊ธฐ

 

1) ํฐํŠธ๋ฅผ ๋‹ค์šด๋ฐ›๊ณ  ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€ํ•œ๋‹ค.

ํ”„๋กœ์ ํŠธ ๋‚ด์— Fonts ํด๋”๋ฅผ ๋งŒ๋“ค์–ด์„œ ๋“œ๋ž˜๊ทธํ•ด์„œ ๋„ฃ๋Š”๋‹ค. ๋„ฃ์„ ๋•Œ ์†์„ฑ์€ ์˜ค๋ฅธ์ชฝ๊ณผ ๊ฐ™์ด ํ•˜๋ฉด ๋œ๋‹ค. Target Check !

 

2) Info.plist ์— font ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

 

3) Text Modifer๋กœ font๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

import SwiftUI

struct ContentView: View {
    var body: some View {
        ZStack {
            Color(red: 1.00, green: 0.69, blue: 0.25)
                .edgesIgnoringSafeArea(.all)
            Text("Yoonsung")
                .font(Font.custom("Pacifico-Regular", size: 40))
                .bold()
                .foregroundColor(.white)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

 

 

 

[๋ฌด๋ฃŒ Font ๋‹ค์šด๋กœ๋“œ ์‚ฌ์ดํŠธ]

https://fonts.google.com/

 

Browse Fonts - Google Fonts

Making the web more beautiful, fast, and open through great typography

fonts.google.com

 

[์ฝ”๋“œ]

๊ธ€์ž์— Font Modifer ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๊ณ , ์•ˆ์— ํฐํŠธ๋ช…์„ ์ž…๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

 

3. ์ด๋ฏธ์ง€ ์ถ”๊ฐ€ํ•˜๊ณ  ๊พธ๋ฏธ๊ธฐ

 

1) Assets ์— ์ด๋ฏธ์ง€๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

 

2) ContentView์— ์ด๋ฏธ์ง€๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๊ณ  ์†์„ฑ์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

import SwiftUI

struct ContentView: View {
    var body: some View {
        ZStack {
            Color(red: 1.00, green: 0.69, blue: 0.25)
                .edgesIgnoringSafeArea(.all)
            VStack {
                Image("apple")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 100.0, height: /*@START_MENU_TOKEN@*/100.0/*@END_MENU_TOKEN@*/)
                    .clipShape(Circle())
                
                Text("Yoonsung")
                    .font(Font.custom("Pacifico-Regular", size: 40))
                    .bold()
                    .foregroundColor(.white)
                
                Text("iOS Developer").foregroundColor(.white)
                    .font(.system(size: 20))
                    .bold()
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

.resizable()์€ ์‚ฌ์ด์ฆˆ๋ฅผ ์žฌ์„ค์ •ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ์†์„ฑ์ด๋‹ค.

.aspectRatio๋Š” ํ™”๋ฉด๋น„์œจ ์„ค์ •, frame์€ ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ์ง์ ‘ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์†์„ฑ์ด๋‹ค.

.clipShape(Circle()) ์€ ์ด๋ฏธ์ง€์˜ ๋ชจ์–‘์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค. Circle()์ด๋ฉด ๋™๊ทธ๋ž€ ๋ชจ์–‘ !

.overlay๋Š” ํ…Œ๋‘๋ฆฌ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค.

 

4. ํ™”๋ฉด ๊ตฌ๋ถ„์ž ๋„ฃ๊ธฐ, ํ…์ŠคํŠธ ๋ฐ•์Šค ๊พธ๋ฉฐ์„œ ๋ฐฐ์น˜ํ•˜๊ธฐ

๋‘ฅ๊ทผ๋ชจ์–‘์˜ ๋„ํ˜• ์œ„์— ์ „ํ™”๊ธฐ ์•„์ด์ฝ˜๊ณผ ์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ–ˆ๋‹ค.

 


import SwiftUI

struct ContentView: View {
    var body: some View {
        ZStack {
            Color(red: 1.00, green: 0.69, blue: 0.25)
                .edgesIgnoringSafeArea(.all)
            VStack {
                Image("apple")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 100.0, height: /*@START_MENU_TOKEN@*/100.0/*@END_MENU_TOKEN@*/)
                    .clipShape(Circle())
                    .overlay(
                        Circle().stroke(Color.gray, lineWidth: 5))
                Text("Yoonsung")
                    .font(Font.custom("Pacifico-Regular", size: 40))
                    .bold()
                    .foregroundColor(.white)
                Text("iOS Developer").foregroundColor(.white)
                    .font(.system(size: 20))
                    .bold()
                Divider()

                Capsule()
                    //.foregroundColor(Color.white)
                    .fill(Color.white)
                    .frame(width: 400, height: 50)
                    .overlay(HStack{
                        Image(systemName: "phone.fill")
                            .foregroundColor(.green)
                        Text("+82 000-0000-0000")
                    })
                    .padding(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)
                
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Divider() ์ด ๊ฐ€๋กœ ๊ตฌ๋ถ„์ž.

 

๋‘ฅ๊ทผ๋„ํ˜•์€ Capsule()์ด๋‚˜ RoundedRectangle()์„ ์ด์šฉํ•˜๋ฉด ๋œ๋‹ค.

๋„ํ˜•์˜ ์ƒ‰์ฑ„์šฐ๊ธฐ๋Š” forgroundColor()๋‚˜ fill() ์†์„ฑ์œผ๋กœ ์ ์šฉ.

 

๋„ํ˜• ์œ„์— ์ด๋ฏธ์ง€์™€ ํ…์ŠคํŠธ๋ฅผ ๋„ฃ์œผ๋ ค๋ฉด overlay() ์†์„ฑ์„ ์“ฐ๋ฉด ๋œ๋‹ค.

์ด๋•Œ ์ด๋ฏธ์ง€์™€ ํ…์ŠคํŠธ๋ฅผ ๊ฐ€๋กœ๋กœ ๋ฐฐ์น˜ํ•ด์•ผ ํ•˜๋ฏ€๋กœ HStack์„ ์ถ”๊ฐ€ํ–ˆ๋‹ค. 

 

๋„ํ˜•์ด ๋„ˆ๋ฌด ์ขŒ์šฐ์— ๋‹ฟ์ง€ ์•Š๊ฒŒ ํŒจ๋”ฉ์„ ์ถ”๊ฐ€ํ–ˆ๋‹ค.

 

5. ๋„ํ˜• ๋ณต์ œํ•ด์„œ ์žฌ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“ค๊ธฐ. ExtractedView !

1) ์›ํ•˜๋Š” ๊ฐ์ฒด๋ฅผ Extracted View ๋กœ ๋บ€๋‹ค.

import SwiftUI

struct ContentView: View {
    var body: some View {
        ZStack {
            Color(red: 1.00, green: 0.69, blue: 0.25)
                .edgesIgnoringSafeArea(.all)
            VStack {
                Image("apple")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 100.0, height: /*@START_MENU_TOKEN@*/100.0/*@END_MENU_TOKEN@*/)
                    .clipShape(Circle())
                    .overlay(
                        Circle().stroke(Color.gray, lineWidth: 5))
                Text("Yoonsung")
                    .font(Font.custom("Pacifico-Regular", size: 40))
                    .bold()
                    .foregroundColor(.white)
                Text("iOS Developer").foregroundColor(.white)
                    .font(.system(size: 20))
                    .bold()
                Divider()

                InfoView()
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

struct InfoView: View{
    var body: some View{
        Capsule()
            .fill(Color.white)
            .frame(width: 400, height: 50)
            .overlay(HStack{
                Image(systemName: "phone.fill")
                    .foregroundColor(.green)
                Text("+82 000-0000-0000")
            })
            .padding(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)
    }
}

 

2) ๊ฐ์ฒด์˜ ํ…์ŠคํŠธ๋ฅผ ์ƒํ™ฉ์— ๋งž๊ฒŒ ๋ฐ”๊ฟ”์ฃผ๊ธฐ ์œ„ํ•ด ๋ณ€์ˆ˜ ๋ฐ ์ธ์ž๋กœ ๋บ€๋‹ค.

 

 

728x90