SwipeViewController is a Swift modification of RKSwipeBetweenViewControllers - navigate between pages / ViewControllers

Overview

SwipeViewController

CI Status Version License Platform Carthage compatible

What is SwipeViewController?

SwipeViewController enables you to modify the navigation bar and implement 'Swipe Buttons' that can user switch pages with and also the user can easily see which page he is on. SwipeViewController is a modification of Objective-C project RKSwipeBetweenViewControllers. I have not only converted the syntax to Swift but added some more functionality and some other minor changes.

demo

Installation

CocoaPods

SwipeViewController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SwipeViewController'

Carthage

If you use Carthage, add this to your Cartfile:

github "fortmarek/SwipeViewController"

Manually

Include the Pod/Classes/SwipeViewController.swift files into your project.

Usage

You can init SwipeViewController simply like this:

let myViewControllerOne = UIViewController() 
let myViewControllerTwo = UIViewController()
let navigationController = SwipeViewController(pages: [myViewControllerOne, myViewControllerTwo])

To set the titles of the buttons, you just need to change the title of each page:

myViewControllerOne.title = "Recent"

This should be done before passing your view controller into the init method of SwipeViewController.

To specify which view controller should be selected first:

// Selecting second view controller as the first
swipeViewController.startIndex = 1

NavigationBar

To change color of the NavigationBar:

swipeViewControler.navigationBarColor = UIColor.blue

You can also include barButtonItems, simply create UIBarButtonItem as you would normally do and then use it like this:

let barButtonItem = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: nil)
leftBarButtonItem = barButtonItem

Note this should be done probably in viewDidLoad (definitely before the view appears).

SwipeButtons

There are two different modes - either every button has the same space on each side not depending on the label size (good for odd numbers)

swipeViewController.equalSpaces = true

or the spaces on each differ depending on the label size (good for even numbers, the label is always centered).

swipeViewController.equalSpaces = false

You can also customize buttons with these properties:

buttonFont, buttonColor, selectedButtonColor

To change the offsets on the side and on the bottom:

swipeViewController.offset = 40 // offset from the side
swipeViewController.bottomOffset = 5 // offset from the bottom

Instead of titles as labels you can use images. First init the button using SwipeButtonWithImage struct:

let buttonOne = SwipeButtonWithImage(image: UIImage(named: "Hearts"), selectedImage: UIImage(named: "YellowHearts"), size: CGSize(width: 40, height: 40))
swipeViewController.buttonsWithImages = [buttonOne, buttonTwo, buttonThree]

SelectionBar

To customize selection bar, you can change these properties:

selectionBarHeight, selectionBarWidth, selectionBarColor

Additional customization

If you want to customize it even more, you can go right to the the SwipeViewController class file but be careful.

Author

fortmarek, [email protected]

License

SwipeViewController is available under the MIT license. See the LICENSE file for more info.

Comments
  • How can I do without

    How can I do without "didFinishLaunchingWithOptions"?

    How can I do without "didFinishLaunchingWithOptions"? For example, how can I call my SwipeViewController in the viewDidAppear method? When the application starts, the first window I have authorization, and then I need to work with SwipeViewController.

    opened by relaxsus 16
  • compile error after upgrade to xCode Version 9.3 (9E145)

    compile error after upgrade to xCode Version 9.3 (9E145)

    On InterfaceController.swift -->

    if buttonDelegate.equalSpaces {
                //Space between buttons
                buttonDelegate.x = (delegate.viewWidth - 2 * buttonDelegate.offset - totalButtonWidth) / CGFloat(buttons.count + 1)
            }
    

    error goes:

    Overlapping accesses to 'buttonDelegate', but modification requires exclusive access; consider copying to a local variable
    
    opened by tempura-shrimp 4
  • It's too dangerous to use too  much hardcode to judge the direction of scrollView

    It's too dangerous to use too much hardcode to judge the direction of scrollView

    As you can see,in theSwipViewController's changeButtonColor method,there are too much hard code to judge the direction of the scrollView,there are many if else things,and all of these if else do not cover all scope,you just consider the scope from -374 to 374,so how it work on iPhone 6 plus,iPhone 6 plus's screen width is 414,it is out of the scope you considered.

    I think this issue maybe has a better solution,like this https://stackoverflow.com/questions/2543670/finding-the-direction-of-scrolling-in-a-uiscrollview How about you?

    opened by EkkoG 4
  • NavigationBar bug ?!

    NavigationBar bug ?!

    Hello! I have a SwipeVC. It`s first window is MenuVC.

    SwipeVC navBar 2018-02-27 17 10 19

    From it I go to VC1.

    self.performSegue(withIdentifier: "writeToDeveloperSegue", sender: self)
    

    From VC1, I show the ImagePicker modal window.

    present(imagePickerController, animated: true, completion: nil)
    

    NavigationBar VC1 2018-02-27 17 10 31

    When I close modal within dismiss method of ImagePicker

    imagePicker.dismiss(animated: true, completion: nil)
    

    Navigation bar from SwipeVC is displayed instead of VC1 navigation bar.

    NavigationBar VC1 after dismiss ImagePicker 2018-02-27 17 10 44

    Do you have any ideas how to deal with that or what am I doing wrong?

    giphy

    opened by relaxsus 3
  • Crash - CGColor not defined for the UIColor

    Crash - CGColor not defined for the UIColor

    Hi, could you see this crash pls? It occurs when itΒ΄s instantiated the SwipeViewController. Without adding any page or setting anything as the documentation explains. The only thing I do is inherit my VC from SwipeViewController

    * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -CGColor not defined for the UIColor <UIPlaceholderColor: 0x7912ebd0>; need to first convert colorspace.'

    Thanks !!

    opened by gariera 3
  • Can use it with Storyboard and UITabBarController

    Can use it with Storyboard and UITabBarController

    if I want use Storyboard and UITabBarController, I can not change AppDelegate function didFinishLaunchingWithOptions rootViewController, I try to this code, but it not work.

    `class mySwipeView: SwipeViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    
        let VC1 = MaybeViewController()
        VC1.view.backgroundColor = UIColor.blueColor()
        VC1.title = "mybe"
        let VC2 = TodayViewController()
        VC2.view.backgroundColor = UIColor(red: 0.70, green: 0.23, blue: 0.92, alpha: 1.0)
        VC2.title = "today"
        let VC3 = HistoryViewController()
        VC3.view.backgroundColor = UIColor(red: 0.17, green: 0.70, blue: 0.27, alpha: 1.0)
        VC3.title = "history"
    
        setViewControllerArray([VC1, VC2, VC3])
        setFirstViewController(0)
        setSelectionBar(80, height: 3, color: UIColor(red: 0.23, green: 0.55, blue: 0.92, alpha: 1.0))
        setButtonsWithSelectedColor(UIFont.systemFontOfSize(18), color: UIColor.blackColor(), selectedColor: UIColor(red: 0.23, green: 0.55, blue: 0.92, alpha: 1.0))
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    }

    class Hiall: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let pageController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
        let navigationController = mySwipeView(rootViewController: pageController)
    

    // navigationController.loadViewIfNeeded() //
    // self.view.addSubview(navigationController.view)

        self.addChildViewController(navigationController)
    
    }
    

    } `

    opened by cougarwww 2
  • met compile error

    met compile error

    XCode 9, compile error in InterfaceController.swift 'NSFontAttributeName' has been renamed to 'NSAttributedStringKey.font' and in SwipeViewController.swift Argument of '#selector' refers to instance method 'switchTabs' that is not exposed to Objective-C

    opened by nillcui 1
  • Put the left swipe button close to the left side of the navigation view, and so does the right side of the navigation view.

    Put the left swipe button close to the left side of the navigation view, and so does the right side of the navigation view.

    I set three swipe buttons on my project. Since I don't need any navigation bar button item, do you know if there is any way to put the left swipe button close to the left side of the navigation view, and so does the right swipe button close to the right side of the navigation view ?

    Thank you so much for the sharing!

    opened by ghost 1
  • Display title on top of the tabs name

    Display title on top of the tabs name

    Hi All !

    Is there a way to display a general title on top of the tab's names ?

    I tried to define a title when I am building my Navigation Bar programmatically, but no title is showing on top of mu three tab's names.

    I suspect what I am doing does not work because the SwipeViewController uses the Navbar's Title to display tab's names.

    Thanks !

    opened by Yungbubu 1
  • black screen

    black screen

    Hey, i tested out your framework, but when im running your example code, all i see is a black screen with a white navigation bar. Theres no visible text at all. Have you experienced this before?

    opened by LitenApe 1
  • Crash when initial view controller should be the first view controller

    Crash when initial view controller should be the first view controller

    Hi,

    In your samples you use setFirstViewController(1) to make the SwipeViewController start on the second view controller.

    If you change this to setFirstViewController(0) (or leave out that line, because 0 is the default value) the SwipeViewController starts without a view controller selected. As soon as you try to swipe, it crashes.

    I have found the issue. Line 83 of SwipeViewController.swift reads guard currentPageIndex > 1 else {return} but it should be guard currentPageIndex >= 1 else {return}

    Kind regards, Hans

    opened by HansZaa 1
  • Error when scrolling to next view controller

    Error when scrolling to next view controller

    I have a bottom bar with just buttons for each button I call:

    if let navController = self.navigationController as? SwipeViewController { navController.scrollToNextViewController(2) }

    But I get this error Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unexpected view controller: <HooHa.ProfileViewController: 0x16006da00>'

    opened by SebastainMisas 1
  • Present View Controller on SwipeView Error

    Present View Controller on SwipeView Error

    Hello Im trying to present a view by calling swipeviewcontroller.present and it works and presents the view but when I dismiss the view all the sudden I cannot swipe to any other views?

    opened by SebastainMisas 1
  • Crash when I open the VC with the Swipe

    Crash when I open the VC with the Swipe

    Hello,

    So, I access this VC with a segue and it works.

    Although, when I tried to make it work with this pod it doesn't open anymore.

    This is my VC's code. Am I missing anything?

    `class PortfolioDetailsVC: SwipeViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let pageController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
        let navigationController = PortfolioDetailsVC(rootViewController: pageController)
        
        let stb = UIStoryboard(name: "Main", bundle: nil)
        let pageOne = stb.instantiateViewController(withIdentifier: "PortfolioDetailsVC") as UIViewController
        let pageTwo = stb.instantiateViewController(withIdentifier: "AutoInvestSettingsVC") as UIViewController
        let pageThree = stb.instantiateViewController(withIdentifier: "AutoInvestOverviewVC") as UIViewController
    
        setViewControllerArray([pageOne])
    
        pageOne.title = "My AutoInvest"
        pageTwo.title = "AutoInvest Settings"
        pageThree.title = "Overview"
    
        setFirstViewController(0)
        setNavigationColor(UIColor.blue)
        equalSpaces = true
       setSelectionBar(80, height: 3, color: .black)
       
    }
    

    }`

    In the image, the highlight is a navigation bar.

    I would love some help.

    Thanks Screenshot 2019-04-11 at 09 16 52

    opened by EduardoGin 2
  • equalSpace = ture show the below error other wise can't get error

    equalSpace = ture show the below error other wise can't get error

    select the equalSpace = true //////////////////////////////////// show the below error buttonDelegate.x = (delegate.viewWidth - 2 * buttonDelegate.offset - totalButtonWidth) / CGFloat(buttons.count + 1)

    opened by rajkumar0143 1
  • Too many buttons,overflow

    Too many buttons,overflow

    overflow If there have too many buttons ,it's not well handled, I wanna it has horizontal scroll. But it collapse together.

    How to make a horizontal scroll.

    I set equalSpace ,and button offset

         equalSpaces = true
        
        setButtonsOffset(10, bottomOffset: 5)
    

    Please help !

    opened by haozes 2
Releases(2.0)
  • 2.0(Jun 16, 2019)

    This release is a refinement of the project with breaking changes - this library no longer depends on subclassing, but you can use the class as-is, any customization can be mode by modifying the instance.

    Besides that, this project now uses Swift 5 and it also provides Carthage binary, so you can build your project quicker.

    Otherwise, the functionality stays the same, enjoy! 😎

    Source code(tar.gz)
    Source code(zip)
    SwipeViewController.framework.zip(1.02 MB)
  • 0.1.7(Sep 7, 2016)

  • 0.1.6(Sep 3, 2016)

  • 0.1.4(Aug 12, 2016)

    Until now, when there was odd count of swipeButtons, the label was not centered. That now changes and you can simply do in your SwipeViewController:

    equalSpaces = false
    

    Of course you can still keep equal spaces, better for odd number of buttons.

    Source code(tar.gz)
    Source code(zip)
  • 0.1.2(Apr 3, 2016)

    For more stable app, I decided that the user won't be able to switch the buttons when there is already swiping animation underway. Also, the app doesn't crash when you just set the view controllers and nothing else.

    Source code(tar.gz)
    Source code(zip)
Owner
Marek FoΕ™t
Marek FoΕ™t
A scroll pager that displays a list of tabs (segments) and manages paging between given views

ScrollPager A scroll pager similar to the one in Flipboard. The control creates a tabbar given a title or an image, and has the option of connecting t

Aryan Ghassemi 512 Aug 31, 2022
UITabBarController with swipe interaction between its tabs.

?? Features Zero setup Different animations Enable/Disable interactions easily Fluid gestures ?? Installation Using CocoaPods Edit your Podfile and sp

Marcos Griselli 1.4k Jan 7, 2023
:octocat: AdaptiveController is a 'Progressive Reduction' Swift UI module for adding custom states to Native or Custom iOS UI elements. Swift UI component by @Ramotion

ADAPTIVE TAB BAR 'Progressive Reduction' module for adding custom states to Native or Custom UI elements. We specialize in the designing and coding of

Ramotion 2k Nov 9, 2022
RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion

ANIMATED TAB BAR Swift UI module library for adding animation to iOS tabbar items and icons.

Ramotion 11k Jan 8, 2023
Aesthetic floating tab bar ––– SwiftUI & Combine ⛓️ Importable via Swift Package Manager πŸ“¦

FloatingTabBar An aesthetic floating tab bar made with SwiftUI & Combine importabable via Swift Package Manager ?? Based off BottomBar-SwiftUI Preview

10011.co 135 Jan 8, 2023
youtube iOS app template written in swift 5

Youtube iOS Template Youtube iOS Template is developed by Haik Aslanyan and written in Swift 3. Purpose of this repo is to show how ViewControllers ca

Henry Aslanyan 2.5k Jan 4, 2023
Pager is the simplest and best way to implement sliding view controllers in Swift

Pager is the simplest and best way to implement sliding view controllers. Installation Drop in the Spring folder to your Xcode project. Or via CocoaPo

Lucas Oceano 234 Aug 5, 2022
Animated top/bottom segmented control written in Swift.

Segmentio Animated top/bottom segmented control written in Swift. Check this project on dribbble. Requirements Xcode 10 iOS 8.x+ Swift 5.0 Installatio

Yalantis 2.4k Jan 9, 2023
A custom tab bar controller for iOS written in Swift 4.2

A custom tab bar controller for iOS written in Swift 4.0 Screenshots Installation Cocoa Pods: pod 'AZTabBar' Swift Package Manager: You can use The Sw

Antonio Zaitoun 335 Dec 11, 2022
πŸ› WormTabStrip ViewPager for iOS written in Swift, which gives continuous feedback to the user when scrolling

Worm Tab Strip Worm Tab Strip is inspired by android SmartTabStrip, android view pager like library for iOS written in swift. Basically it was build u

EzimetYusup 176 Dec 13, 2022
Aesthetic floating tab bar ––– SwiftUI & Combine ⛓️ Importable via Swift Package Manager πŸ“¦

FloatingTabBar An aesthetic floating tab bar made with SwiftUI & Combine importabable via Swift Package Manager ?? Based off BottomBar-SwiftUI Preview

10011.co 134 Jan 5, 2023
CustomTabBar - A Custom TabBar Built Using Swift

CustomTabBar Thanks to Riccardo Cipolleschi for his awesome tutorial. The TabBar

SM Arif Ahmed 1 Feb 14, 2022
Swipe between pages with an interactive title navigation control. Configure horizontal or vertical chains for unlimited pages amount.

SlideController is a simple and flexible UI component fully written in Swift. Built using power of generic types, it is a nice alternative to UIPageVi

Touchlane 409 Dec 6, 2022
Swipe between pages with an interactive title navigation control. Configure horizontal or vertical chains for unlimited pages amount.

SlideController is a simple and flexible UI component fully written in Swift. Built using power of generic types, it is a nice alternative to UIPageVi

Touchlane 411 Jan 5, 2023
A tool for Swift code modification intermediating between code generation and formatting.

swift-mod A tool for Swift code modification intermediating between code generation and formatting. Overview swift-mod is a tool for Swift code modifi

Ryo Aoyama 95 Nov 3, 2022
Custom transition between viewcontrollers holding tableviews

Custom transition between viewcontrollers holding tableviews. Each cell is animated to simulate a 'wave effect'. Read more about transitions here and

Andrea Mazzini 2.4k Dec 21, 2022
PassValuesBetweenViewControllers - Pass Values Between ViewControllers

PassValuesBetweenViewControllers Vista creada con: Programmatic + AutoLayout Bre

Vanesa Giselle Korbenfeld 0 Jan 18, 2022
πŸ“±πŸ“² Navigate between view controllers with ease. πŸ’« πŸ”œ More stable version (written in Swift 5) coming soon.

CoreNavigation ?? ?? Navigate between view controllers with ease. ?? ?? More stable version (written in Swift 5) coming soon. Getting Started API Refe

Aron Balog 69 Sep 21, 2022
πŸ„β€β™‚οΈ UITextField-Navigation makes it easier to navigate between UITextFields and UITextViews

' __________________ _______ _________ _______ _________ _______ _ ______ ' |\ /|\__ __/\__ __/( ____ \|\ /

Thanh Pham 446 Nov 24, 2022
SwiftWebKit - This app look like a browser, but you can navigate between 2 sites

import UIKit import WebKit My first app for WebKit. This app look like a browser

Ahmet Onur Şahin 3 Apr 18, 2022