Notice
Recent Posts
Recent Comments
Link
ยซ   2024/05   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

lgvv98

[SwiftUI] List (tableView in UIKit) ๋ณธ๋ฌธ

apple/๐Ÿš SwiftUI & Combine

[SwiftUI] List (tableView in UIKit)

๐Ÿฅ• ์บ๋Ÿฟ๋งจ 2022. 5. 18. 16:24

List (tableView in UIKit)

 

โœ… SwiftUI์˜ List์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž.

List๋ฅผ ๊ตฌ์„ฑํ•˜๋Š”๊ฑด ํฌ๊ฒŒ ์–ด๋ ต์ง€ ์•Š๋‹ค.

 

 

โœ… MyList

import SwiftUI

struct MyList: View {
    
    // ๋‹ค๋ฅธ์ชฝ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์˜ฌ ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—
    @Binding var isNavigationBarHidden: Bool
    
    // ๋ฐ”์ธ๋”ฉ์˜ ๊ฒฝ์šฐ์—๋Š” ์ƒ์„ฑ์ž ํ•„์ˆ˜!
    init(isNavigationBarHidden: Binding<Bool> = .constant(false)) {
        
        if #available(iOS 14.0, *){
            
        } else {
        	// ์•„๋ž˜ ๋ฒ„์ „์—์„œ๋Š” ํ‘ธํ„ฐ๊ฐ€ ์žˆ์–ด์„œ ์ด ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด์„œ ์—†์• ์•ผ ํ•œ๋‹ค.
            UITableView.appearance().tableFooterView = UIView()
        }
        
        UITableView.appearance().separatorStyle = .none // ๊ตฌ๋ถ„์„  ์—†์• ๊ธฐ
        
        // ๋‚ด๋ถ€์˜ self.isNavigationBarHidden = isNavigationBarHidden๋ž‘ ๊ฐ™์€ ์˜๋ฏธ
        _isNavigationBarHidden = isNavigationBarHidden
        
    }
    
    var body: some View{
        
//        List{
//            Text("๋งˆ์ด๋ฆฌ์ŠคํŠธ")
//            Text("๋งˆ์ด๋ฆฌ์ŠคํŠธ")
//            Text("๋งˆ์ด๋ฆฌ์ŠคํŠธ")
//            Text("๋งˆ์ด๋ฆฌ์ŠคํŠธ")
//            Text("๋งˆ์ด๋ฆฌ์ŠคํŠธ")
//            Text("๋งˆ์ด๋ฆฌ์ŠคํŠธ")
//        }
        
//        List{
//            ForEach(1...10, id: \.self){
//                Text("๋งˆ์ด๋ฆฌ์ŠคํŠธ \($0)")
//            }
//        }
        
        List{
            // ์„น์…˜์„ ์ค„ ์ˆ˜ ์žˆ์–ด
            Section( 
            	// ์„น์…˜์˜ ํ—ค๋” ์„ธํŒ…
                header: 
                Text("์˜ค๋Š˜ ํ•  ์ผ")
                    .font(.headline)
                    .foregroundColor(Color.black)
                
                // ์„น์…˜์˜ ํ‘ธํ„ฐ์„ธํŒ…
                ,footer: Text("footer")
            ) { 
            	// ํ•˜๋‚˜์˜ ์„น์…˜์— ์•„์ดํ…œ 3๊ฐœ ๋งŒ๋“ฆ
                ForEach(1...3, id: \.self){ itemIndex in
                    MyCard(icon: "book.fill", title: "์ฑ…์ฝ๊ธฐ \(itemIndex)", start: "1 PM", end: "3 PM", bgColor: Color.green)
                    
                }
            }
            // ์„น์…˜์˜ list์˜ ๊ฐ row์— inset์„ ์–ผ๋งˆ๋‚˜ ์ค„์ง€ ์„ ํƒ
            .listRowInsets(EdgeInsets.init(top: 10, leading: 10, bottom: 10, trailing: 10))
            
            Section(header:
                Text("๋‚ด์ผ ํ•  ์ผ")
                    .font(.headline)
                    .foregroundColor(Color.black)
            ) {
                ForEach(1...20, id: \.self){ itemIndex in
                	// ์•„์ดํ…œ์˜ ๋ฐฐ๊ฒฝ์€ ์—ฌ๊ธฐ์„œ ์ฒ˜๋ฆฌ ํ•ด์•ผํ•ด!
                    MyCard(icon: "book.fill", title: "์ฑ…์ฝ๊ธฐ \(itemIndex)", start: "1 PM", end: "3 PM", bgColor: Color.blue)
                }
            }
            .listRowInsets(EdgeInsets.init(top: 10, leading: 10, bottom: 10, trailing: 10))
            .listRowBackground(Color.yellow) // ๊ฐ row์˜ ๋ฐฐ๊ฒฝ์ƒ‰
            
        }
        .listStyle(GroupedListStyle()) // ๋ฆฌ์ŠคํŠธ์˜ ์Šคํƒ€์ผ ์„ ํƒ
//        .listStyle(PlainListStyle())
        .navigationBarTitle("๋‚ด ๋ชฉ๋ก") // ๋ฆฌ์ŠคํŠธ์—์„œ ๋„ค๋น„๊ฒŒ์ด์…˜ ํƒ€์ดํ‹€ ์ฃผ๊ธฐ
//        .navigationBarHidden(self.isNavigationBarHidden)
        .onAppear { // onAppear๋Š” ๋ณด์—ฌ์งˆ ๋•Œ ๋‚˜ํƒ€๋‚˜๋Š” ์†์„ฑ
            self.isNavigationBarHidden = false // ๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฐ”๊ฐ€ hidden๋˜์ง€ ์•Š๊ฒŒ๋”
        }
        
    } // NavigationView
}

 

โœ… ContentView

import SwiftUI

struct ContentView: View {
    
    @State var isNavigationBarHidden : Bool = false // contentView์—์„œ๋Š” ๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฐ”๋ฅผ ๊ฐ€๋ฆผ
    
    var body: some View {
    	NavigationLink(
        	destination: MyList (
            	isNavigationBarHidden: self.$isNavigationBarHidden // ๋‹ฌ๋Ÿฌ์‹ธ์ธ ์ฃผ์˜
           	)
		) {
			Image(systemName: "line.horizontal.3")
				.font(.largeTitle)
				.foregroundColor(Color.black)
        } // NavigationLink
    } // body
} // ContentView

 

 

์œ„์˜ ์ฝ”๋“œ๋“ค์„ ์„ค๋ช…ํ•˜์ž๋ฉด contentView์—์„œ๋Š” ๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฐ”๋ฅผ ๊ฐ€๋ฆฌ๊ณ  ๋‹ค์Œ ํŽ˜์ด์ง€๋กœ ๋„˜์–ด๊ฐ”์„ ๋•Œ ํ™œ์„ฑํ™”ํ•˜๊ธฐ ์œ„ํ•จ!

 

'apple > ๐Ÿš SwiftUI & Combine' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[SwiftUI] GeometryReader  (0) 2022.05.19
[SwiftUI] NavigationView  (0) 2022.05.18
[SwiftUI] Alert  (0) 2022.05.18
[SwiftUI] VStack, HStack, ZStack  (0) 2022.05.18
[SwiftUI] How to set Image in SwiftUI  (0) 2022.05.18
Comments