Coder Social home page Coder Social logo

shabib87 / shviewpager Goto Github PK

View Code? Open in Web Editor NEW
125.0 11.0 25.0 1.07 MB

A simple view pager for iOS. Compatible with iOS 8.0 or later.

Home Page: https://www.codewithshabib.com

License: MIT License

Objective-C 70.21% Ruby 1.63% Swift 8.32% Shell 19.84%
swift pager objective-c viewpager swift3 objective-c-library

shviewpager's Introduction

SHViewPager

SHViewPager

Version License Platform

  • A simple view pager for iOS, which acts similar to android's viewPager. Compatible with iOS 8.0 or later. Supports iPhones and iPads in all interface orientation.

Table of contents

Preview

iPhone interface:

iPhone screen

iPad interface:

iPad screen

Advantages

  • Supports both Swift (v2.2 and v3.0) and Objective-C
  • Supports all orientations
  • Supports iPad
  • Supports Autolayout

Demo project

Fully workable examples; both in Objective-C and Swift; are included. If you want to try it yourself, just download/checkout this repository, and run pod install from the Example directory first. Then open the SHViewPager.xcworkspace with Xcode.

Requirements

  • Xcode 6+
  • iOS 8+
  • ARC

Installation

###Cocoapods

Recommended way

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

use_frameworks!
target '<YourTarget>' do
	pod 'SHViewPager', '~> 2.0'
end

###Source files

  1. Download the latest code version or add the repository as a git submodule to your git-tracked project.
  2. Drag and drop the Classes and the Resources directory from the archive in your project navigator. Make sure to select Copy items when asked if you extracted the code archive outside of your project.

Use SHViewPager wherever you need it with #import <SHViewPager/SHViewPagerModule.h> in Objective-C and import SHViewPager in Swift.

##How to use

The SHViewPager needs it's datasource and delegate protocols to be implemented. Simply initialize it from code or better:

Method 1

  1. Drag and drop an UIView from the Storyboard to your UIViewController.
  2. Change the class to SHViewPager, and
  3. Finally connect the datasource, delegate and your property IBOutlet.

Method 2

  1. Drag and drop an UIViewController to the Storyboard.
  2. Change the class to SHViewPagerController

Four datasource methods are required and others are optional.

Objective-C: The required datasource methods are

- (NSInteger)numberOfPagesInViewPager:(SHViewPager *)viewPager;
- (UIViewController *)containerControllerForViewPager:(SHViewPager *)viewPager;
- (UIViewController *)viewPager:(SHViewPager *)viewPager controllerForPageAtIndex:(NSInteger)index;

and,

- (NSString *)viewPager:(SHViewPager *)viewPager titleForPageMenuAtIndex:(NSInteger)index;

or,

- (UIImage *)viewPager:(SHViewPager *)viewPager imageForPageMenuAtIndex:(NSInteger)index;

Swift: The required datasource methods are

func numberOfPages(in viewPager: SHViewPager) -> Int
func containerController(for viewPager: SHViewPager) -> UIViewController
func viewPager(_ viewPager: SHViewPager, controllerForPageAt index: Int) -> UIViewController

and,

func viewPager(_ viewPager: SHViewPager, titleForPageMenuAt index: Int) -> String

or,

func viewPager(_ viewPager: SHViewPager, imageForPageMenuAt index: Int) -> UIImage

To display the contents, you need to call the instance method reloadData in your desired method block; typically in viewDidLoad; and pagerWillLayoutSubviews in viewWillLayoutSubviews.

-Example:

Objective-C

- (void)viewDidLoad {
    [super viewDidLoad];
    // your code
    [viewPager reloadData];
}

-(void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    [_pager pagerWillLayoutSubviews];
}

Swift

override func viewDidLoad() {
    super.viewDidLoad()
    // your code
    pager.reloadData()
}

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    pager.pagerWillLayoutSubviews()
}

Known Issues

Please refer to the open issue list.

Author

Created by Ahmad Shabibul Hossain, @shabib_hossain on 5/15/14.

Contact

Share feedbacks and ideas to improve this project, I would love to hear them out. You can also follow me on @shabib_hossain.

License

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

shviewpager's People

Contributors

andrewsage avatar pirocso avatar shabib87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shviewpager's Issues

Vertical scrolling disabled

Hey the view pager is not showing the full contents of the view controller at index, means there is no vertical scrolling to show the full contents. Can I modify it to use Custom Views instead of UIVIewController for every page index?

Scroll view content offset reset

When a UIViewController is pushed over the UIViewController that has the SHViewPager, on popping that top UIViewController the content offset of the scroll view of the SHViewPager is reset to zero (0) regardless of the last position of the content offset.

I dont see tabs, just content , I can swipe controllers...

When I pause debug I see that topTabScroll has zero height. index indicator image view is also zero height. header tittle label has height 18 but I dont see it eather. What to do ?

I setup way that I changed one view to SHViewPager in designer xib. Implemented everything as written on page.

Screen rotation

Hey;

Can you please tell me how to support rotating? When I rotate the screen from portrait to landscape, the size of the pager doesn't change and sticking to the left side of the screen.

Portrait:

screen shot 2014-09-16 at 11 09 09

Landscape

screen shot 2014-09-16 at 11 09 24

Thanks

Memory leak on setUpContentViewForTargetIndex:

When a view controllers view is loaded and the user moves to the next menu, and comes back to the first chosen menu, the view controllers view is again added as a subview. Creating unnecessary memory cogs.

Is there a way to use it with React Native?

I understand this is only for iOS, but can we bring it to JavaScript as React Native component only for iOS because Android natively supports top tabs.

This will help us to have more performance than the JS implementations out there.

I've seen the JS implementations are really bad when it comes to performance with lots of data.

Update to storyboard

Get rid of the old way to initiate view controllers and move towards storyboards in the example project.

dealloc issue

Dear author, sorry to bother you.

I have encountered a dealloc issue during using this excellent library, and will be really appreciate your help.

I use SHViewPager in a container viewController which will be pushed in and poped out , the pager's dataSource contains two blank viewControllers which are just initialized to take the test, then, there is the issue, when i pop out this container viewController, none of the three viewControllers' dealloc method is been called, which i guess can be named a memory leak.

So, can you test the library again and make sure wether there is a dealloc issue.

thank you again.

Update examples

Update the current library example to most recent manner.

Position of page menu

Is it possible to modify the page menu's position? Right now it is anchored at the top of the view but I'd rather see it below the viewpager.

Dismissing Image Picker Controller (presented from any ViewController inside ViewPager) takes control to first ViewController of ViewPager

I am using this pager. thanks!

I am using SHViewPager as UIView and showing all view controllers inside this view pager.

When I present an image picker controller from any viewcontroller of viewpager, everything works fine.

The problem is when I dismiss an image controller, the viewpager shows the first viewcontroller of viewpager which is not an expected behavior, pager should show the viewcontroller from which it was presented.

Please check.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.