[SwiftUI] TwitterClone: Feed UI

Junyoung ParkΒ·2022λ…„ 11μ›” 15일
0

SwiftUI

λͺ©λ‘ 보기
97/136
post-thumbnail

πŸ”΄ Let's Build Twitter with SwiftUI (iOS 15, Xcode 13, Firebase, SwiftUI 3.0)

TwitterClone: Get Started

κ΅¬ν˜„ λͺ©ν‘œ

  • ν”„λ‘œμ νŠΈ 생성 및 νŠΈμœ„ν„° ν”Όλ“œ UI κ΅¬ν˜„

κ΅¬ν˜„ νƒœμŠ€ν¬

  • λ°˜λ³΅λ˜λŠ” νŠΈμœ„ν„° λ·° κ΅¬ν˜„

μ†ŒμŠ€ μ½”λ“œ

import SwiftUI

struct FeedView: View {
    var body: some View {
        ScrollView {
            LazyVStack {
                ForEach(0...20, id: \.self) { _ in
                    TweetRowView()
                        .padding()
                }
            }
        }
    }
}
  • μ—¬λŸ¬ 개의 ν”Όλ“œκ°€ 반볡적으둜 λ“€μ–΄μ˜€λ―€λ‘œ λ·° μž¬μ‚¬μš©
import SwiftUI

struct TweetRowView: View {
    var body: some View {
        VStack(alignment: .leading) {
            // profile image + user info + tweet
            HStack(alignment: .top, spacing: 12) {
                profileImageView
                VStack(alignment: .leading, spacing: 4) {
                    // user info
                    userInfoView
                    // tweet caption
                    captionView
                }
            }
            // action button
            HStack {
                messageButton
                Spacer()
                arrowButton
                Spacer()
                heartButton
                Spacer()
                bookmarkButton
            }
            .padding()
            .foregroundColor(.gray)
            Divider()
        }
    }
}
  • ν”„λ‘œν•„ 이미지, μœ μ € 정보, νŠΈμœ„νŠΈ λ“± 반볡 정보 및 λ²„νŠΌ
extension TweetRowView {
    private var profileImageView: some View {
        Circle()
            .frame(width: 56, height: 56)
            .foregroundColor(Color(.systemBlue))
    }
    
    private var userInfoView: some View {
        HStack {
            Text("Rober Dawny Junior")
                .font(.subheadline)
                .bold()
            Text("@Ironman")
                .foregroundColor(.gray)
                .font(.caption)
            Text("2w")
                .foregroundColor(.gray)
                .font(.caption)
        }
    }
    
    private var captionView: some View {
        Text("I'm Ironman")
            .font(.subheadline)
            .multilineTextAlignment(.leading)
    }
    
    private var messageButton: some View {
        Button {
            // action for button
        } label: {
            Image(systemName: "bubble.left")
                .font(.subheadline)
        }
    }
    
    private var arrowButton: some View {
        Button {
            // action for button
        } label: {
            Image(systemName: "arrow.2.squarepath")
                .font(.subheadline)
        }
    }
    
    private var heartButton: some View {
        Button {
            // action for button
        } label: {
            Image(systemName: "heart")
                .font(.subheadline)
        }
    }
    
    private var bookmarkButton: some View {
        Button {
            // action for button
        } label: {
            Image(systemName: "bookmark")
                .font(.subheadline)
        }
    }
}
  • μ΅μŠ€ν…μ…˜μ„ ν†΅ν•œ λ³„λ„μ˜ λ·° 관리

κ΅¬ν˜„ ν™”λ©΄

SwiftUI 볡슡 κ²Έ decentν•œ UI κ΅¬ν˜„ 방법을 λ‹€μ‹œ!

profile
JUST DO IT

0개의 λŒ“κΈ€