SwiftUI/SwiftUI(Basic)66 17. [SwiftUI] @State property wrapper 뷰가 변수의 상태 변화를 관찰하도록! 만약 변수에 변화가 생기면 뷰를 업데이트 한다. https://toughie-ios.tistory.com/108 [SwiftUI] PropertyWrapper, @State, @Binding 스스챌 에러를 해결하던 중.. @State와 @Binding을 사용하는 경우도 많았고, 해당 개념이 있었다면 더 빠르게 해결 할 수 있었을 문제도 있어서 간단하게 정리해보려 한다. Property wrapper 우선 프로퍼 toughie-ios.tistory.com 아래는 @State변수를 활용한 뷰의 변화를 보여주기 위한 간단한 예시이다. 버튼을 누르거나 스와이프를 하면 배경색, 타이틀, 카운트가 바뀐다. // Created by Toughie o.. 2023. 4. 21. 16. [SwiftUI] Button() Button(_ title:action:) -> String title로 간편하게 만들 수 있음 Button(action:label:) -> label에는 어떤 view든 올 수 있음 (커스터마이징 자유롭게 가능) action에는 버튼이 눌렸을 때 작동할 원하는 동작을 클로저로 전달하면 되고 label에는 원하는 뷰로 버튼의 모습을 커스터마이징 할 수 있다. // Created by Toughie on 2023/04/20. // import SwiftUI struct Buttons: View { @State var title: String = "This is fancy title" var body: some View { VStack(spacing: 20) { Text(title) .font(.largeT.. 2023. 4. 20. 15. [SwiftUI] .ignoresSafeArea() & .edgesIgnoringSafeArea() https://developer.apple.com/design/human-interface-guidelines/foundations/layout/ Layout - Foundations - Human Interface Guidelines - Design - Apple Developer Layout Using a consistent layout that adapts to various contexts makes your experience more approachable and helps people enjoy their favorite apps and games on all their devices. Guides and safe areas A layout guide defines a rectangular .. 2023. 4. 20. 14. [SwiftUI] LazyVGrid, LazyHGrid, GridItems Lazy 를 통해 좀 더 효율적으로 데이터 로드가 가능 (lazy 아니면 일부 데이터만 필요한데, 전체 데이터 로드하는 경우가 생길 수 있음) flexible을 자주 사용. 스크롤뷰와 함께 응용 (pinnedViews에 header) LazyHGrid는 방향만 Horizontal이고 다 동일하다. // Created by Toughie on 2023/04/19. // import SwiftUI struct Grids: View { let colors: [Color] = [Color.blue, Color.red, Color.yellow] let columns: [GridItem] = [ GridItem(.flexible(), spacing: 6, alignment: nil), GridItem(.flexib.. 2023. 4. 19. [SwiftUI] PropertyWrapper, @State, @Binding 스스챌 에러를 해결하던 중.. @State와 @Binding을 사용하는 경우도 많았고, 해당 개념이 있었다면 더 빠르게 해결 할 수 있었을 문제도 있어서 간단하게 정리해보려 한다. Property wrapper 우선 프로퍼티 래퍼(@붙은 녀석들)가 무엇인지 알아보자. '랩으로 감싼다' 프로퍼티를 특정 타입으로 감싸서 추가적인 동작이나 기능을 가진 프로퍼티를 선언할 때 쓰인다. 이 타입은 PropertyWrapper 프로토콜을 준수하고, 프로퍼티 읽기/쓰기 (get, set) 에서의 동작을 정의한다. SwiftUI에서 Property wrapper는 데이터 상태 관리를 심플하게 하는데 자주 쓰인다. 대표적인 프로퍼티 래퍼가 @State, @Binding 이다. @State 프로퍼티의 값이 변경될 때 뷰를 .. 2023. 4. 13. 13. [SwiftUI] ScrollView / LazyVStack & LazyHStack 파라미터 axes -> .vertical(수직 스크롤), .horizontal(수평 스크롤) showIndicators -> 스크롤 하면 오른쪽에 회색 바 표시할지 말 지( bool ) content -> () -> View 타입 클로저 스크롤뷰를 만드는 것은 간단하다. 그럼 수직, 수평 스크롤 다 되는 화면을 만들어 보자 ! // Created by Toughie on 2023/04/13. // import SwiftUI struct ScrollViewPrac: View { var body: some View { ScrollView { LazyVStack { ForEach(0.. 2023. 4. 13. 이전 1 ··· 5 6 7 8 9 10 11 다음