티스토리 뷰

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
32
33
34
35
36
37
38
import SwiftUI
 
struct ContentView: View {
    init(){
        let myAppearance = UINavigationBarAppearance()
        myAppearance.titleTextAttributes = [.foregroundColor : UIColor.blue, .font : UIFont.italicSystemFont(ofSize: 30)]
        myAppearance.largeTitleTextAttributes = [.foregroundColor : UIColor.purple]
        myAppearance.backgroundColor = UIColor.orange
 
        UINavigationBar.appearance().standardAppearance = myAppearance
        UINavigationBar.appearance().tintColor = UIColor.black
    }
    
    var body: some View {
        NavigationView{
        List{
            NavigationLink(
                destination: Text("Destination"),
                label: {
                    HStack{
                        Image(systemName: "person")
                        Text("Navigate")
                    }
                })
            Text("Hi")
            Text("Hi")
        }
        .navigationBarTitle("Hello", displayMode: .large)
        }
    }
}
 
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
 
cs

- init() 에서 navigationView의 UI 꾸밈.

- UiNavigationBarAppearance()

   : titleTextAttributes(상단 Bar text 설정), largeTitleTextAttributes(Title 설정), backgroundColor(상단 Bar background 설정)

- tintColor는 destination화면의 상단 Bar 글씨 색 설정

- navigationLink 로 화면 이동 구현. 

- 28행의 .navigationBarTitle 에서 title과 모드를 정할 수 있음. (.large 와 .inline)

 

.large (좌), .inline(우)
destination화면

 

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   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
글 보관함