iOS/SwiftUI


struct PlayerView: View{ @State private var isPlaying: Bool = false var body: some View{ PlayButton(isPlaying: $isPlaying) }}struct PlayButton: View{ @Binding var isPlaying: Bool var body: some View{ Button(action:{ self.isPlaying.toggle() }){ Image(systemName:isPlaying ? "pause.circle" : "play.circle") } }}사용자 인터페이스(UI) 상태 관리앱의 View 계층 구조..


GeometryReaderA container view that defines its content as a function of its own size and coordinate space.→ content의 고유한 Size와 좌표 공간의 함수로 정의하는 Container View→ 자식 뷰에 부모 뷰와 기기에 대한 크기 및 좌표계 정보를 전달하는 기능을 수행함GeometryReader{ _ in Circle().fill(Color.purple) .frame(width: 200, height: 200) .overlay(Text("Center").font(.title))}.background(Color.gray) GeometryProxy@available(iOS 13.0, ..


List하나의 열에 여러 개의 행으로 표현되는 UI를 구성해 다중 데이터를 쉽게 나열할 수 있는 구성된 ViewUIKit에서 동일한 역할을 하던 UITableView와 비교적 사용법이 간소화 됨List{ ForEach(0.. 동적 콘텐츠에서 사용 방식Range 동적 콘텐츠로 Range 타입을 넘겨줌Half-Open Range Operator(Range) A.. 다른 범위 연산자는 사용 불가List(0..RandomAccessCollection Protocol1. id로 사용할 값을 직접 인수로 지정// Hashable 프로토콜 준수 시에는 간편하게 self로 사용List(["A", "B", "C", "D", "E"], id: \.self){ Text("\($0)")} 2. Identifiabl..


Button 액션을 시작하는 가장 기본적인 컨트롤 UIKit의 UIButton과 같은 역할 기본적인 Button의 선언 Button(action: { // 버튼 액션 }){ Text("버튼") // Button Title } Button 사용 HStack(spacing: 20){ // 첫 번째 버튼 Button("Button"){ print("Button1") } // 두 번째 버튼 Button(action: { print("Button2") }){ Text("Button") .padding() .background(RoundedRectangle(cornerRadius: 10.0).strokeBorder()) } // 세 번째 버튼 Button(action:{print("Button3")}){ Circl..


Spacer Spacer | Apple Developer Documentation A flexible space that expands along the major axis of its containing stack layout, or on both axes if not contained in a stack. developer.apple.com 주축을 포함하는 Stack Layout에서 팽창하거나 Stack 안에서 두 축 위에 포함되지 않는 유연한 빈 공간 Spacer는 뷰와 대응하여 내용 없이 최대로 팽창하며 생성할 수 있습니다. 아래는 Spacer를 활용한 예시 코드입니다. 1. Spacer를 사용하기 전의 코드 struct ChecklistRow: View { let name: String var ..


HStack : 수평방향(Horizontal)으로 Stack을 쌓는 View HStack | Apple Developer Documentation A view that arranges its subviews in a horizontal line. developer.apple.com var body: some View { HStack( alignment: .top, spacing: 10 ) { ForEach( 1...5, id: \.self ) { Text("Item \($0)") } } } Result Code에서 ForEach문이 등장한다. ForEach : 식별된 데이터의 기본 컬렉션에서 요구에 따라 View를 계산하는 Structure ForEach | Apple Developer Documenta..