본문 바로가기

iOS/SwiftUI

(16)
SwiftUI 텍스트 포맷 빠르게 알아보기 💫 Currencystruct CurrencyView: View { private let 💰 = 100_000 var body: some View { VStack { Text(💰, format: .currency(code: "KRW")) Text(💰, format: .currency(code: "USD")) Text(💰, format: .currency(code: "GBP")) } }}code에는 ISO-4217 코드를 찾아서 입력하면 된다. 원화는 소숫점을 표시하지 않지만 달러나 파운드 스털링같은 경우에는 소숫점 둘째자리까지 표시해준다.💫 Percentstruct PercentView:..
SwiftUI의 AttributedString사용해보기 (feat. hacking with swift) https://www.hackingwithswift.com/quick-start/swiftui/how-to-add-advanced-text-styling-using-attributedstring 위 글을 참고하여 구현한 전체 코드 및 미리보기 미리보기 샘플 코드 import SwiftUI struct ContentView: View { var body: some View { VStack(spacing: 10) { Case1() Case2() Case3() Case4() Case5() Case6() Case7() Case8() Case9() } } } #Preview { ContentView() } struct Case1: View { var message: AttributedString { var res..
SwiftUI Bordering (inside, half, outside) extension View { func insideBorder( _ content: C, shape: S = Rectangle(), lineWidth: CGFloat = 1 ) -> some View where C: ShapeStyle, S: InsettableShape { overlay( shape .strokeBorder(content, lineWidth: lineWidth) ) } func halfBorder( _ content: C, shape: S = Rectangle(), lineWidth: CGFloat = 1 ) -> some View where C: ShapeStyle, S: InsettableShape { overlay( shape .stroke(content, lineWidth: li..
SwiftUI에서 GoogleMapsAPI 적용해보기 - 심화 기초편에서 이어지는 내용이므로 이전 포스팅을 보고 오는것을 추천합니다. 💫 화면을 클릭해서 새로운 마커를 찍어보기 1. GMSMapViewDelegate 추가 extension GMSMapViewRepresentable.Coordinator: GMSMapViewDelegate { // 화면을 클릭할 때마다 실행 func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) { let marker = GMSMarker(position: coordinate) marker.snippet = "\(coordinate.latitude)\n\(coordinate.longitude)" marker.icon = GMSMarker.mark..
SwiftUI에서 GoogleMapsAPI 적용해보기 - 기초 우선 공식문서를 보고 프로젝트에 GoogleMaps에 관한 설정을 마쳐놓자. 💫 지도화면 띄워보기 1. API Key 등록 import SwiftUI import GoogleMaps @main struct GoogleMapsTutorialApp: App { init() { GMSServices.provideAPIKey("YOUR_API_KEY") } var body: some Scene { WindowGroup { ContentView() } } } 공식문서에서는 AppDelegate에서 API키를 등록하지만 SwiftUI에서 @main 어노테이션이 있는 객체의 init()에서 등록해도 된다. 2. GMSMapView를 UIViewRepresentable로 감싸기 import SwiftUI import ..
Alignment Guides 💫 Custom alignment guides Apple 공식문서 Apple Developer Documentation developer.apple.com private struct FirstThirdAlignment: AlignmentID { static func defaultValue(in context: ViewDimensions) -> CGFloat { context.height / 3 } } extension VerticalAlignment { static let firstThird = VerticalAlignment(FirstThirdAlignment.self) } 해당 뷰 높이의 3분의 1지점을 정렬하는 FirstThirdAlignment를 새로 만들고 VerticalAlignment에서 스..
SwiftUI로 CheckBoxTreeView 만들기! 💫 완성화면 git: https://github.com/lee-chance/CheckBoxTreeView 💫 각각의 데이터가 될 객체 만들기 struct Node: Identifiable { typealias ID = String let id: ID let label: String let children: [Node]? init(id: ID = UUID().uuidString, label: String, children: [Node]? = nil) { self.id = id self.label = label self.children = children } init(_ label: String, children: [Node]? = nil) { self.id = label self.label = label ..
SwiftUI로 Countdown Timer 만들어보기 💫 Timer를 활용한 방법 struct ContentView: View { var body: some View { VStack { Text("Timer") TimerCountdownTimer() } .frame(maxWidth: .infinity, maxHeight: .infinity) .padding() } } struct TimerCountdownTimer: View { @State private var timeRemaining = 10 private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() var body: some View { ZStack { if timeRemaining > 0 { Text("\(time..