Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Apple-esque animated welcome screen for iOS and iPadOS. Configurable.

License

NotificationsYou must be signed in to change notification settings

slawaDnC/UIOnboarding

 
 

Repository files navigation

UIOnboarding

UIOnboarding is an animated, configurable welcome screen in a Swift Package – inspired by Apple'sStocks app.

It supports iPhone, iPad and iPod touch running iOS and iPadOS 13 or higher, including core accessibility features such as Dynamic Type, Reduce Motion and VoiceOver for all devices – Split View and Slide Over for iPad.

Developed and designed byLukman Aščić.


Table of Contents

Previews

iPhone and iPod touch

Default 6.5"Default 4"
UIOnboarding Preview 6.5 inch

iPad

12.9" Portrait12.9" Landscape
UIOnboarding Preview 12.9 inch PortraitUIOnboarding Preview 12.9 inch Landscape

Split View

1/3 iPad Landscape1/2 iPad Landscape2/3 iPad Landscape
UIOnboarding Slit View 1/3 LandscapeUIOnboarding Slit View 1/2 LandscapeUIOnboarding Slit View 2/3 Landscape
1/3 iPad Portrait2/3 iPad Portrait
UIOnboarding Slit View 1/3 PortraitUIOnboarding Slit View 2/3 Portrait

Slide Over

iPad PortraitiPad Landscape
UIOnboarding Slide Over PortraitUIOnboarding Slide Over Landscape

Accessibility

Dynamic TypeVoiceOverReduce Motion
UIOnboarding Preview Dynamic TypeUIOnboarding Preview VoiceOverUIOnboarding Preview Redcue Motion

Installation

Swift Package Manager

Addhttps://github.com/lascic/UIOnboarding.git in the package manager in Xcode underFile > Add Packages. Select the version from2.0.0 or themain branch.

.package(url:"https://github.com/lascic/UIOnboarding.git", from:"2.0.0")// or.package(url:"https://github.com/lascic/UIOnboarding.git", branch:"main")

Demo Project

Three demo projects can be found in the/Demo directory, including an example for utilizing UIOnboarding in a SwiftUI app.

Clone the repo or download the demo projects as a .zip file to open and run them on a physical device or simulator in Xcode.

Before building and running the projects, make sure to set them up with your own provisioning profile.

Usage

UIOnboardingViewControllertakes aUIOnboardingViewConfiguration parameter for setup.

UIKit

Make sure the view controller you're presenting from is embedded in aUINavigationController.OnboardingViewController has been set up to be presented as a full screen view.

// In the view controller you're presentingimport UIKitimport UIOnboardingletonboardingController:UIOnboardingViewController=.init(withConfiguration:.setUp())onboardingController.delegate=selfnavigationController?.present(onboardingController, animated:false)

Dismiss the onboarding view with the provided delegate method.

extensionViewController:UIOnboardingViewControllerDelegate{func didFinishOnboarding(onboardingViewController:UIOnboardingViewController){        onboardingViewController.modalTransitionStyle=.crossDissolve        onboardingViewController.dismiss(animated:true, completion:nil)}}

SwiftUI

SwiftUI'sUIViewControllerRepresentable protocol makes the UIKitUIOnboardingViewController behave as a SwfitUIView.

Create anOnboardingView struct implementing the protocol and use the.fullScreenCover() modifier introduced in iOS and iPadOS 14 to show it in the SwiftUI view you're presenting from.

.fullScreenCover(isPresented: $showingOnboarding, content:{OnboardingView.init().edgesIgnoringSafeArea(.all)}

Note that we assign SwiftUI's coordinator as the delegate object for our onboarding view controller.

onboardingController.delegate= context.coordinator

Full Setup

// In OnboardingView.swiftimport SwiftUIimport UIOnboardingstructOnboardingView:UIViewControllerRepresentable{typealiasUIViewControllerType=UIOnboardingViewControllerfunc makeUIViewController(context:Context)->UIOnboardingViewController{letonboardingController:UIOnboardingViewController=.init(withConfiguration:.setUp())        onboardingController.delegate= context.coordinatorreturn onboardingController}func updateUIViewController(_ uiViewController:UIOnboardingViewController, context:Context){}classCoordinator:NSObject,UIOnboardingViewControllerDelegate{func didFinishOnboarding(onboardingViewController:UIOnboardingViewController){            onboardingViewController.dismiss(animated:true, completion:nil)}}func makeCoordinator()->Coordinator{return.init()}}
// In ContentView.swiftimport SwiftUIstructContentView:View{@StateprivatevarshowingOnboarding=truevarbody:someView{NavigationView{Text("Hello, UIOnboarding!").toolbar{Button{                        showingOnboarding=true} label:{Image(systemName:"repeat")}}.fullScreenCover(isPresented: $showingOnboarding, content:{OnboardingView.init().edgesIgnoringSafeArea(.all)})}}}structContentView_Previews:PreviewProvider{staticvarpreviews:someView{ContentView.init()}}

Configuration

UIOnboardingViewConfiguration consists of six, non-optional component types.

  1. App Icon asUIImage
  2. First Welcome Title Line asNSMutableAttributedString
  3. Second Welcome Title Line asNSMutableAttributedString
  4. Core Features asArray<UIOnboardingFeature>
  5. Notice Text asUIOnboardingTextViewConfiguration (e.g. Privacy Policy, Terms of Service, Portfolio, Website)
  6. Continuation Title asUIOnboardingButtonConfiguration

Create a helper structUIOnboardingHelper defining these components and combine them in anextension ofUIOnboardingViewConfiguration.

Example

import UIKitimport UIOnboardingstructUIOnboardingHelper{    // App Iconstaticfunc setUpIcon()->UIImage{returnBundle.main.appIcon??.init(named:"onboarding-icon")!}    // First Title Line    // Welcome Textstaticfunc setUpFirstTitleLine()->NSMutableAttributedString{.init(string:"Welcome to", attributes:[.foregroundColor:UIColor.label])}        // Second Title Line    // App Namestaticfunc setUpSecondTitleLine()->NSMutableAttributedString{.init(string:Bundle.main.displayName??"Insignia", attributes:[.foregroundColor:UIColor.init(named:"camou")!])}    // Core Featuresstaticfunc setUpFeatures()->Array<UIOnboardingFeature>{return.init([.init(icon:.init(named:"feature-1")!,                  title:"Search until found",                  description:"Over a hundred insignia of the Swiss Armed Forces – each redesigned from the ground up."),.init(icon:.init(named:"feature-2")!,                  title:"Enlist prepared",                  description:"Practice with the app and pass the rank test on the first run."),.init(icon:.init(named:"feature-3")!,                  title:"#teamarmee",                  description:"Add name tags of your comrades or cadre. Insignia automatically keeps every name tag you create in iCloud.")])}    // Notice Textstaticfunc setUpNotice()->UIOnboardingTextViewConfiguration{return.init(icon:.init(named:"onboarding-notice-icon")!,                     text:"Developed and designed for members of the Swiss Armed Forces.",                     linkTitle:"Learn more...",                     link:"https://www.lukmanascic.ch/portfolio/insignia",                     tint:.init(named:"camou"))}    // Continuation Titlestaticfunc setUpButton()->UIOnboardingButtonConfiguration{return.init(title:"Continue",                     titleColor:.white, // Optional, `.white` by default                     backgroundColor:.init(named:"camou")!)}}

Welcome Title Localization

If the welcome title only needs one line (in another language for example), simply provide an emptyNSMutableAttributedString value for either parameter.UIOnboardingTitleLabelStack automatically resizes itself to the corresponding line count, with no additional changes needed.

Below an example in Portuguese, leaving the second title line blank.

// First Title Line// App Namestaticfunc setUpFirstTitleLine()->NSMutableAttributedString{return.init(string:Bundle.main.displayName??"Distintivos", attributes:[.foregroundColor:UIColor.init(named:"camou")!])}// Second Title Line// Emptystaticfunc setUpSecondTitleLine()->NSMutableAttributedString{return.init(string:"")}

Extension

import UIOnboardingextensionUIOnboardingViewConfiguration{    // UIOnboardingViewController initstaticfunc setUp()->UIOnboardingViewConfiguration{return.init(appIcon:UIOnboardingHelper.setUpIcon(),                     firstTitleLine:UIOnboardingHelper.setUpFirstTitleLine(),                     secondTitleLine:UIOnboardingHelper.setUpSecondTitleLine(),                     features:UIOnboardingHelper.setUpFeatures(),                     textViewConfiguration:UIOnboardingHelper.setUpNotice(),                     buttonConfiguration:UIOnboardingHelper.setUpButton())}}

Further Setup

You may present the weclome screen only once (on first app launch) with the help of aUser Defaults flag. Note that an unspecified UserDefaultsbool(forKey:) key is set tofalse by default.

if !UserDefaults.standard.bool(forKey:"hasCompletedOnboarding"){showOnboarding()}

Toggle onboarding completion in the provided delegate method.

func didFinishOnboarding(onboardingViewController:OnboardingViewController){    onboardingViewController.modalTransitionStyle=.crossDissolve    onboardingViewController.dismiss(animated:true){UserDefaults.standard.set(true, forKey:"hasCompletedOnboarding")}}

Further Readings

Copyright

UIOnboarding isMIT licensed.

TheInsignia app icon andInsignia feature cell assets are copyright Lukman Aščić. All rights reserved. None of these materials or parts of it may be reproduced or distributed by any means without prior written permission of the copyright owner.

About

Apple-esque animated welcome screen for iOS and iPadOS. Configurable.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift100.0%

[8]ページ先頭

©2009-2025 Movatter.jp