Use CocoaPod Paper OnBoarding with xib file Swift 4



1. create new file (cocoa touch class)



import UIKit
import paper_onboarding

class Onboarding: PaperOnboarding {

}
                      

2. create class file Onboarding.swift and connect with UIView





3. after that use this code below



import paper_onboarding
import UIKit

class OnBoardingViewController: UIViewController {
    @IBOutlet var onBoardingObj: Onboarding!
    @IBOutlet weak var skipB: UIButton!
    @IBOutlet weak var bDaftar: UIButton!
    @IBOutlet weak var pageControl: UIPageControl!
    
    fileprivate let items = [
        OnboardingItemInfo(title: "Selamat Datang",
                           informationImage: #imageLiteral(resourceName: "intro1"),
                           description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit estibulum nisl nibh, placerat vitae est sed.",
                           pageIcon: #imageLiteral(resourceName: "active"),
                           color: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0),
                           titleColor: UIColor.gray,
                           descriptionColor: UIColor.gray,
                           titleFont: titleFont,
                           descriptionFont: descriptionFont),
        
        OnboardingItemInfo(title: "Partner Asuransi",
                           informationImage: #imageLiteral(resourceName: "intro2"),
                           description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit estibulum nisl nibh, placerat vitae est sed.",
                           pageIcon: #imageLiteral(resourceName: "active"),
                           color: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0),
                           titleColor: UIColor.gray,
                           descriptionColor: UIColor.gray,
                           titleFont: titleFont,
                           descriptionFont: descriptionFont),
        
        OnboardingItemInfo(title: "Daftar Sekarang!",
                           informationImage: #imageLiteral(resourceName: "intro3"),
                           description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit estibulum nisl nibh, placerat vitae est sed.",
                           pageIcon: #imageLiteral(resourceName: "active"),
                           color: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0),
                           titleColor: UIColor.gray,
                           descriptionColor: UIColor.gray,
                           titleFont: titleFont,
                           descriptionFont: descriptionFont)
        
    ]
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        onBoardingObj.dataSource = self
        onBoardingObj.delegate = self
        bDaftar.isHidden = true
        self.pageControl.hidesForSinglePage = true


    }
    
    
    @IBAction func bDaftarB(_ sender: UIButton) {
        let vc = LoginViewController()
        self.navigationController?.setViewControllers([vc], animated: true)
    }
    
    @IBAction func skipBut(_ sender: UIButton) {
        let vc = LoginViewController()
        self.navigationController?.setViewControllers([vc], animated: true)
    }
}

extension OnBoardingViewController: PaperOnboardingDelegate {
    
    func onboardingWillTransitonToIndex(_ index: Int) {
//        skipB.isHidden = index == 2 ? false : true
        self.pageControl.currentPage = index
        if index != 2 {
            if bDaftar.isHidden == false {
                bDaftar.isHidden = true
                skipB.isHidden = false
            }
        }
        
    }
    
    func onboardingDidTransitonToIndex(_ index: Int) {
        if index == 2 {
            bDaftar.isHidden = false
            skipB.isHidden = true
        }
            
    }
    
    func onboardingConfigurationItem(_ item: OnboardingContentViewItem, index: Int) {
        //item.titleLabel?.backgroundColor = .redColor()
        //item.descriptionLabel?.backgroundColor = .redColor()
        //item.imageView = ...
    }
}

extension OnBoardingViewController: PaperOnboardingDataSource {
    func onboardingItemsCount() -> Int {
        return 3
    }
    
    func onboardingItem(at index: Int) -> OnboardingItemInfo {
        return items[index]
    }
}

extension OnBoardingViewController {
    
    private static let titleFont = UIFont(name: "Nunito-Bold", size: 14.0) ?? UIFont.boldSystemFont(ofSize: 15.0)
    private static let descriptionFont = UIFont(name: "OpenSans-Regular", size: 12.0) ?? UIFont.systemFont(ofSize: 14.0)
}

or download this link







No comments: