Bài đăng

Đang hiển thị bài đăng từ Tháng 6, 2023

Swift UI : ScrollView vs List

Hình ảnh
ScrollView                          ScrollView {                              Text ( "Alo" )                              Text ( "Alo" )                              Text ( "Alo" )                              Text ( "Alo" )                              Text ( "Alo" )                              Text ( "Alo" )                              Text ( "Alo" )               ...

Swift UI note

SwiftUI uses Declarative Syntax. Swift uses Imperative Syntax. Declarative Syntax lets you specify what you want to be created and the system decides how to do it. Imperative Syntax forces you to describe exactly how you want an interface item to be created. Zstack, Vstack, Zstack       ZStack {             Color . accentColor                 . ignoresSafeArea ()             HStack ( spacing : 20 ){                 Text ( "Demo" ). scaledToFit (). frame ( width : 100 , height : 100 , alignment : . center ). border (. red )                 VStack ( alignment : . trailing , spacing : 30 ){                     Text ( "Tomato Tortellini, Bottarga and Carbonara " ). font (. title3 )                    ...

Swift UI : Observable, Observed, State and Binding

State and Binding @State and @Binding are used when you need to pass a variable to another view.   struct ContentView : View { @State var showLogo = true var body : some View { VStack { if showLogo { LittleLemonLogo (bindingVariable : $showLogo) } } } } @State to controlling a variable "showLogo" struct LittleLemonLogo : View { @Binding var bindingVariable : Bool var body : some View { VStack { Image ( "littleLemonLogo" ) Button (action : { bindingVariable. toggle () } , label : { Text ( "Toggle Logo Visibility" ) . font (. title2 ) }) } } } A Boolean variable named bindingVariable of type @Binding is created on line 1 . This variable will receive the state of ContentView 's showLogo variable and will be tied to it, meaning, that any ...