Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing multi-line title, image reduction, Objective-C compatibility, font configuration, and padding. Added support for "next" button instead of "skip", as well. Adding delegate callback for providing access to content view controllers when displayed/redisplayed. #28

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
14 changes: 7 additions & 7 deletions AlertOnboarding/AlertChildPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

import UIKit

class AlertChildPageViewController: UIViewController {
@objc public class AlertChildPageViewController: UIViewController {

var pageIndex: Int!
internal(set) var pageIndex: Int!

@IBOutlet weak var image: UIImageView!
@IBOutlet weak var labelMainTitle: UILabel!
@IBOutlet weak var labelDescription: UILabel!
@objc @IBOutlet public private(set) weak var image: UIImageView!
@objc @IBOutlet public private(set) weak var labelMainTitle: UILabel!
@objc @IBOutlet public private(set) weak var labelDescription: UILabel!

override func viewDidLoad() {
override public func viewDidLoad() {
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
override public func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
12 changes: 6 additions & 6 deletions AlertOnboarding/AlertChildPageViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
<view contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ozM-3f-JWg" userLabel="View 2:2">
<frame key="frameInset" minY="314" width="600" height="286"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="CHOOSE THE PLANET" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="64e-Bi-ts0">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="CHOOSE THE PLANET" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="64e-Bi-ts0">
<frame key="frameInset" minX="8" minY="8" width="584" height="57"/>
<fontDescription key="fontDescription" name="Avenir-Heavy" family="Avenir" pointSize="17"/>
<color key="textColor" red="0.6705882353" green="0.69411764710000001" blue="0.76862745099999996" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="5" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eh1-05-M15">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eh1-05-M15">
<frame key="frameInset" minX="8" minY="92" width="584" height="21"/>
<string key="text">Lorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsum</string>
<fontDescription key="fontDescription" name="Avenir-Book" family="Avenir" pointSize="13"/>
Expand All @@ -37,12 +37,12 @@
</label>
</subviews>
<constraints>
<constraint firstItem="64e-Bi-ts0" firstAttribute="leading" secondItem="ozM-3f-JWg" secondAttribute="leading" constant="10" id="9bY-Oy-RjP"/>
<constraint firstAttribute="trailing" secondItem="eh1-05-M15" secondAttribute="trailing" constant="10" id="D32-SW-K7R"/>
<constraint firstItem="64e-Bi-ts0" firstAttribute="leading" secondItem="ozM-3f-JWg" secondAttribute="leading" constant="14" id="9bY-Oy-RjP"/>
<constraint firstAttribute="trailing" secondItem="eh1-05-M15" secondAttribute="trailing" constant="14" id="D32-SW-K7R"/>
<constraint firstItem="eh1-05-M15" firstAttribute="top" secondItem="64e-Bi-ts0" secondAttribute="bottom" constant="10" id="cpQ-i1-7gA"/>
<constraint firstAttribute="trailing" secondItem="64e-Bi-ts0" secondAttribute="trailing" constant="10" id="fTP-Ao-j9O"/>
<constraint firstAttribute="trailing" secondItem="64e-Bi-ts0" secondAttribute="trailing" constant="14" id="fTP-Ao-j9O"/>
<constraint firstItem="eh1-05-M15" firstAttribute="centerX" secondItem="ozM-3f-JWg" secondAttribute="centerX" id="mFw-fv-u7r"/>
<constraint firstItem="eh1-05-M15" firstAttribute="leading" secondItem="ozM-3f-JWg" secondAttribute="leading" constant="10" id="put-D4-Yuc"/>
<constraint firstItem="eh1-05-M15" firstAttribute="leading" secondItem="ozM-3f-JWg" secondAttribute="leading" constant="14" id="put-D4-Yuc"/>
<constraint firstItem="64e-Bi-ts0" firstAttribute="top" secondItem="ozM-3f-JWg" secondAttribute="top" constant="10" id="rib-H8-35l"/>
</constraints>
</view>
Expand Down
53 changes: 36 additions & 17 deletions AlertOnboarding/AlertOnboarding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

import UIKit

public protocol AlertOnboardingDelegate {
@objc public protocol AlertOnboardingDelegate {
func alertOnboardingSkipped(_ currentStep: Int, maxStep: Int)
func alertOnboardingCompleted()
func alertOnboardingNext(_ nextStep: Int)

@objc optional func alertOnboardingDidDisplayStep(alertOnboarding: AlertOnboarding, alertChildPageViewController: AlertChildPageViewController, step: Int)
}

open class AlertOnboarding: UIView, AlertPageViewDelegate {
Expand All @@ -28,30 +30,37 @@ open class AlertOnboarding: UIView, AlertPageViewDelegate {


//PUBLIC VARS ------------------------
open var colorForAlertViewBackground: UIColor = UIColor.white
@objc open var colorForAlertViewBackground: UIColor = UIColor.white

@objc open var colorButtonBottomBackground: UIColor = UIColor(red: 226/255, green: 237/255, blue: 248/255, alpha: 1.0)
@objc open var colorButtonText: UIColor = UIColor(red: 118/255, green: 125/255, blue: 152/255, alpha: 1.0)

open var colorButtonBottomBackground: UIColor = UIColor(red: 226/255, green: 237/255, blue: 248/255, alpha: 1.0)
open var colorButtonText: UIColor = UIColor(red: 118/255, green: 125/255, blue: 152/255, alpha: 1.0)
@objc open var colorTitleLabel: UIColor = UIColor(red: 171/255, green: 177/255, blue: 196/255, alpha: 1.0)
@objc open var colorDescriptionLabel: UIColor = UIColor(red: 171/255, green: 177/255, blue: 196/255, alpha: 1.0)

open var colorTitleLabel: UIColor = UIColor(red: 171/255, green: 177/255, blue: 196/255, alpha: 1.0)
open var colorDescriptionLabel: UIColor = UIColor(red: 171/255, green: 177/255, blue: 196/255, alpha: 1.0)
@objc open var fontTitleLabel: UIFont? = UIFont(name: "Avenir-Heavy", size: 17);
@objc open var fontDescriptionLabel: UIFont? = UIFont(name: "Avenir-Book", size: 13);
@objc open var fontButtonText: UIFont? = UIFont(name: "Avenir-Black", size: 15);

open var colorPageIndicator = UIColor(red: 171/255, green: 177/255, blue: 196/255, alpha: 1.0)
open var colorCurrentPageIndicator = UIColor(red: 118/255, green: 125/255, blue: 152/255, alpha: 1.0)
@objc open var colorPageIndicator = UIColor(red: 171/255, green: 177/255, blue: 196/255, alpha: 1.0)
@objc open var colorCurrentPageIndicator = UIColor(red: 118/255, green: 125/255, blue: 152/255, alpha: 1.0)

open var heightForAlertView: CGFloat!
open var widthForAlertView: CGFloat!

open var percentageRatioHeight: CGFloat = 0.8
open var percentageRatioWidth: CGFloat = 0.8
@objc open var percentageRatioHeight: CGFloat = 0.8
@objc open var percentageRatioWidth: CGFloat = 0.8

@objc open var nextInsteadOfSkip = false

open var titleSkipButton = "SKIP"
open var titleGotItButton = "GOT IT !"
@objc open var titleNextButton = "NEXT"
@objc open var titleSkipButton = "SKIP"
@objc open var titleGotItButton = "GOT IT !"

open var delegate: AlertOnboardingDelegate?
@objc open var delegate: AlertOnboardingDelegate?


public init (arrayOfImage: [String], arrayOfTitle: [String], arrayOfDescription: [String]) {
@objc public init (arrayOfImage: [String], arrayOfTitle: [String], arrayOfDescription: [String]) {
super.init(frame: CGRect(x: 0,y: 0,width: 0,height: 0))
self.configure(arrayOfImage, arrayOfTitle: arrayOfTitle, arrayOfDescription: arrayOfDescription)
self.arrayOfImage = arrayOfImage
Expand All @@ -77,7 +86,7 @@ open class AlertOnboarding: UIView, AlertPageViewDelegate {
// MARK: PUBLIC FUNCTIONS --------------------------------------------------------------
//-----------------------------------------------------------------------------------------

open func show() {
@objc open func show() {

//Update Color
self.buttonBottom.backgroundColor = colorButtonBottomBackground
Expand Down Expand Up @@ -106,7 +115,7 @@ open class AlertOnboarding: UIView, AlertPageViewDelegate {
}

//Hide onboarding with animation
open func hide(){
@objc open func hide(){
self.checkIfOnboardingWasSkipped()
DispatchQueue.main.async { () -> Void in
self.animateForEnding()
Expand Down Expand Up @@ -134,7 +143,7 @@ open class AlertOnboarding: UIView, AlertPageViewDelegate {
fileprivate func configure(_ arrayOfImage: [String], arrayOfTitle: [String], arrayOfDescription: [String]) {

self.buttonBottom = UIButton(frame: CGRect(x: 0,y: 0, width: 0, height: 0))
self.buttonBottom.titleLabel?.font = UIFont(name: "Avenir-Black", size: 15)
self.buttonBottom.titleLabel?.font = fontButtonText
self.buttonBottom.addTarget(self, action: #selector(AlertOnboarding.onClick), for: .touchUpInside)

self.background = UIView(frame: CGRect(x: 0,y: 0, width: 0, height: 0))
Expand Down Expand Up @@ -218,6 +227,16 @@ open class AlertOnboarding: UIView, AlertPageViewDelegate {
//MARK: BUTTON ACTIONS ---------------------------------

@objc func onClick(){
if (nextInsteadOfSkip) {
if let viewController = self.container.viewControllerAtIndex((self.container.pageController.viewControllers?[0] as! AlertChildPageViewController).pageIndex!-1)
{
self.container.pageController.setViewControllers([viewController], direction: UIPageViewControllerNavigationDirection.forward, animated: true, completion: nil)
self.container.didMoveToPageIndex(pageIndex: (viewController as! AlertChildPageViewController).pageIndex)

return;
}
}

self.hide()
}

Expand Down
30 changes: 26 additions & 4 deletions AlertOnboarding/AlertPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class AlertPageViewController: UIViewController, UIPageViewControllerDataSource,
override func viewDidLoad() {
super.viewDidLoad()

if (alertview.nextInsteadOfSkip) {
self.alertview.buttonBottom.setTitle(alertview.titleNextButton, for: UIControlState())
}

self.configurePageViewController()
self.configurePageControl()

Expand Down Expand Up @@ -95,6 +99,9 @@ class AlertPageViewController: UIViewController, UIPageViewControllerDataSource,


func viewControllerAtIndex(_ index : Int) -> UIViewController? {
if (index<0 || index>=arrayOfImage.count) {
return nil;
}

var pageContentViewController: AlertChildPageViewController!
let podBundle = Bundle(for: self.classForCoder)
Expand All @@ -116,18 +123,23 @@ class AlertPageViewController: UIViewController, UIPageViewControllerDataSource,
let realIndex = arrayOfImage.count - index - 1

pageContentViewController.image.image = UIImage(named: arrayOfImage[realIndex])
pageContentViewController.image.layer.minificationFilter=kCAFilterTrilinear
pageContentViewController.labelMainTitle.font = alertview.fontTitleLabel
pageContentViewController.labelMainTitle.text = arrayOfTitle[realIndex]
pageContentViewController.labelMainTitle.textColor = alertview.colorTitleLabel
pageContentViewController.labelDescription.font = alertview.fontDescriptionLabel
pageContentViewController.labelDescription.text = arrayOfDescription[realIndex]
pageContentViewController.labelDescription.textColor = alertview.colorDescriptionLabel

return pageContentViewController
}

func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
let pageContentViewController = pageViewController.viewControllers![0] as! AlertChildPageViewController
let index = pageContentViewController.pageIndex
self.currentStep = (arrayOfImage.count - index! - 1)
didMoveToPageIndex(pageIndex: (pageViewController.viewControllers![0] as! AlertChildPageViewController).pageIndex)
}

func didMoveToPageIndex(pageIndex: Int) {
self.currentStep = (arrayOfImage.count - pageIndex - 1)
self.delegate?.nextStep(self.currentStep)
//Check if user watching the last step
if currentStep == arrayOfImage.count - 1 {
Expand All @@ -138,13 +150,21 @@ class AlertPageViewController: UIViewController, UIPageViewControllerDataSource,
self.maxStep = currentStep
}
if pageControl != nil {
pageControl.currentPage = arrayOfImage.count - index! - 1
pageControl.currentPage = arrayOfImage.count - pageIndex - 1
if pageControl.currentPage == arrayOfImage.count - 1 {
self.alertview.buttonBottom.setTitle(alertview.titleGotItButton, for: UIControlState())
} else if (alertview.nextInsteadOfSkip) {
self.alertview.buttonBottom.setTitle(alertview.titleNextButton, for: UIControlState())
} else {
self.alertview.buttonBottom.setTitle(alertview.titleSkipButton, for: UIControlState())
}
}

if self.alertview.delegate?.alertOnboardingDidDisplayStep != nil {
(self.alertview.delegate?.alertOnboardingDidDisplayStep)!(self.alertview, (self.pageController.viewControllers?.first)! as! AlertChildPageViewController, self.currentStep)

}

}


Expand Down Expand Up @@ -189,6 +209,8 @@ class AlertPageViewController: UIViewController, UIPageViewControllerDataSource,
self.viewControllers = [initialViewController!]
self.pageController.setViewControllers(viewControllers, direction: .forward, animated: false, completion: nil)

didMoveToPageIndex(pageIndex: arrayOfImage.count-1)

self.addChildViewController(self.pageController)
}

Expand Down