{"id":32741,"date":"2024-11-01T09:11:13","date_gmt":"2024-11-01T09:11:13","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32741"},"modified":"2024-11-01T11:23:56","modified_gmt":"2024-11-01T11:23:56","slug":"swiftui-style-iphone-app-development-go-to-page-09-page-control","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32741\/","title":{"rendered":"SwiftUI Style, iPhone App Development, Go to Page 09 &#8211; Page Control"},"content":{"rendered":"<p><body><\/p>\n<p>The user interface (UI) is very important when developing applications for iPhone or iPad. The success of the app is often related to the user experience (UI\/UX), and SwiftUI is a powerful tool for creating this innovative user interface. In this post, we will take a closer look at how to transition between pages using page control in iPhone app development with SwiftUI.<\/p>\n<h2>What is SwiftUI?<\/h2>\n<p>SwiftUI is a user interface toolkit developed by Apple, based on the Swift programming language. It combines modern syntax with a reactive programming model, allowing you to build UIs declaratively. With SwiftUI, you can create complex UIs with just a few lines of code and provide a consistent experience across all Apple devices.<\/p>\n<h2>What is Page Control?<\/h2>\n<p>Page control is a UI element used to navigate multiple pages. It shows the user&#8217;s current page position and allows easy transitions by swiping or pressing buttons. This is especially useful in apps that require tutorials, image galleries, or multiple screens.<\/p>\n<h2>Implementing Page Control in SwiftUI<\/h2>\n<p>Now, let\u2019s look at how to implement page control using SwiftUI step by step. We will begin by explaining the basic code structure.<\/p>\n<h3>1. Create a Basic Project<\/h3>\n<p>Open Xcode and create a new project. Choose the &#8216;App&#8217; template, enter the project name, and select SwiftUI. This project will be the base for this guide.<\/p>\n<h3>2. Add Necessary Libraries<\/h3>\n<p>While you don\u2019t need to add special libraries to use SwiftUI, you need to use ObservableObject and State to manage data in the SwiftUI declarative context.<\/p>\n<h3>3. Create a Page View Model<\/h3>\n<p>To manage the pages, you need to create a ViewModel. This model is responsible for maintaining the current page and handling page transitions.<\/p>\n<pre class=\"example\">\nstruct PageData: Identifiable {\n    let id = UUID()\n    let title: String\n    let content: String\n}\n<\/pre>\n<h3>4. Create Page Models<\/h3>\n<p>Generate data to be used for the page model. For example, let&#8217;s assume there are pages with simple strings.<\/p>\n<pre class=\"example\">\nclass PageViewModel: ObservableObject {\n    @Published var currentPage: Int = 0\n    let pages: [PageData] = [\n        PageData(title: \"Page 1\", content: \"This is the first page.\"),\n        PageData(title: \"Page 2\", content: \"This is the second page.\"),\n        PageData(title: \"Page 3\", content: \"This is the third page.\"),\n    ]\n}\n<\/pre>\n<h3>5. Create a Page View<\/h3>\n<p>Now let&#8217;s create a view to display each page. In SwiftUI, you can combine views to create a complex UI.<\/p>\n<pre class=\"example\">\nstruct PageView: View {\n    @ObservedObject var viewModel: PageViewModel\n\n    var body: some View {\n        VStack {\n            Text(viewModel.pages[viewModel.currentPage].title)\n                .font(.largeTitle)\n                .padding()\n\n            Text(viewModel.pages[viewModel.currentPage].content)\n                .font(.body)\n                .padding()\n\n            PageControl(currentPage: $viewModel.currentPage, numberOfPages: viewModel.pages.count)\n                .padding()\n        }\n    }\n}\n<\/pre>\n<h3>6. Create a Page Control<\/h3>\n<p>To implement page control, you need to create a SwiftUI view that wraps the UIKit&#8217;s UIPageControl.<\/p>\n<pre class=\"example\">\nstruct PageControl: UIViewRepresentable {\n    @Binding var currentPage: Int\n    var numberOfPages: Int\n\n    func makeUIView(context: Context) -> UIPageControl {\n        let control = UIPageControl()\n        control.numberOfPages = numberOfPages\n        control.addTarget(context.coordinator, action: #selector(Coordinator.pageChanged(_:)), for: .valueChanged)\n        return control\n    }\n\n    func updateUIView(_ uiView: UIPageControl, context: Context) {\n        uiView.currentPage = currentPage\n    }\n\n    func makeCoordinator() -> Coordinator {\n        return Coordinator(self)\n    }\n\n    class Coordinator: NSObject {\n        var control: PageControl\n\n        init(_ control: PageControl) {\n            self.control = control\n        }\n\n        @objc func pageChanged(_ sender: UIPageControl) {\n            control.currentPage = sender.currentPage\n        }\n    }\n}\n<\/pre>\n<h3>7. Final Combination<\/h3>\n<p>Now that all components are ready, let\u2019s combine them and display them on the screen.<\/p>\n<pre class=\"example\">\nstruct ContentView: View {\n    @StateObject var viewModel = PageViewModel()\n\n    var body: some View {\n        PageView(viewModel: viewModel)\n    }\n}\n<\/pre>\n<h2>Code Explanation<\/h2>\n<p>The above code has a complete structure for manipulating pages.<\/p>\n<ul>\n<li><strong>Getting Started:<\/strong> Create a new SwiftUI app project and implement the <code>PageViewModel<\/code> class to manage the necessary data.<\/li>\n<li><strong>UI Structure:<\/strong> Define <code>PageView<\/code> to show each page\u2019s title and content.<\/li>\n<li><strong>Implementing Page Control:<\/strong> Use <code>UIPageControl<\/code> to visually represent the current page and receive user input.<\/li>\n<li><strong>Overall Combination:<\/strong> Combine all components through <code>ContentView<\/code>.<\/li>\n<\/ul>\n<h2>Testing and Debugging<\/h2>\n<p>After writing the above code, run the app in the Simulator to check if the page transitions work correctly. Verify that the page control functions properly and that the contents of each page are displayed correctly.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we explored how to create page controls and implement transitions between pages using SwiftUI. SwiftUI is a highly useful tool for managing user interfaces and leveraging various resources to provide a better user experience. Continue to utilize SwiftUI to develop amazing apps!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The user interface (UI) is very important when developing applications for iPhone or iPad. The success of the app is often related to the user experience (UI\/UX), and SwiftUI is a powerful tool for creating this innovative user interface. In this post, we will take a closer look at how to transition between pages using &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32741\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;SwiftUI Style, iPhone App Development, Go to Page 09 &#8211; Page Control&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-32741","post","type-post","status-publish","format-standard","hentry","category-swift-iphone-app-development-swiftui"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SwiftUI Style, iPhone App Development, Go to Page 09 - Page Control - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32741\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SwiftUI Style, iPhone App Development, Go to Page 09 - Page Control - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"The user interface (UI) is very important when developing applications for iPhone or iPad. The success of the app is often related to the user experience (UI\/UX), and SwiftUI is a powerful tool for creating this innovative user interface. In this post, we will take a closer look at how to transition between pages using &hellip; \ub354 \ubcf4\uae30 &quot;SwiftUI Style, iPhone App Development, Go to Page 09 &#8211; Page Control&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32741\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:11:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:23:56+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32741\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32741\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"SwiftUI Style, iPhone App Development, Go to Page 09 &#8211; Page Control\",\"datePublished\":\"2024-11-01T09:11:13+00:00\",\"dateModified\":\"2024-11-01T11:23:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32741\/\"},\"wordCount\":527,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Swift iPhone app development (SwiftUI)\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32741\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32741\/\",\"name\":\"SwiftUI Style, iPhone App Development, Go to Page 09 - Page Control - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:11:13+00:00\",\"dateModified\":\"2024-11-01T11:23:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32741\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32741\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32741\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SwiftUI Style, iPhone App Development, Go to Page 09 &#8211; Page Control\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SwiftUI Style, iPhone App Development, Go to Page 09 - Page Control - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32741\/","og_locale":"ko_KR","og_type":"article","og_title":"SwiftUI Style, iPhone App Development, Go to Page 09 - Page Control - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"The user interface (UI) is very important when developing applications for iPhone or iPad. The success of the app is often related to the user experience (UI\/UX), and SwiftUI is a powerful tool for creating this innovative user interface. In this post, we will take a closer look at how to transition between pages using &hellip; \ub354 \ubcf4\uae30 \"SwiftUI Style, iPhone App Development, Go to Page 09 &#8211; Page Control\"","og_url":"https:\/\/atmokpo.com\/w\/32741\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:11:13+00:00","article_modified_time":"2024-11-01T11:23:56+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32741\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32741\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"SwiftUI Style, iPhone App Development, Go to Page 09 &#8211; Page Control","datePublished":"2024-11-01T09:11:13+00:00","dateModified":"2024-11-01T11:23:56+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32741\/"},"wordCount":527,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Swift iPhone app development (SwiftUI)"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32741\/","url":"https:\/\/atmokpo.com\/w\/32741\/","name":"SwiftUI Style, iPhone App Development, Go to Page 09 - Page Control - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:11:13+00:00","dateModified":"2024-11-01T11:23:56+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32741\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32741\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32741\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"SwiftUI Style, iPhone App Development, Go to Page 09 &#8211; Page Control"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32741"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32741\/revisions"}],"predecessor-version":[{"id":32742,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32741\/revisions\/32742"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}