TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Oct 2016 |
Maintained by Shabib Hossain.
iPhone interface:
iPad interface:
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.
Use SHViewPager wherever you need it with #import <SHViewPager/SHViewPagerModule.h>
in Objective-C and import SHViewPager
in Swift.
The SHViewPager
needs it's datasource
and delegate
protocols to be implemented. Simply initialize it from code or better:
Method 1
UIView
from the Storyboard to your UIViewController
.SHViewPager
, and datasource
, delegate
and your property IBOutlet
.Method 2
UIViewController
to the Storyboard.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()
}
Please refer to the open issue list.
Created by Ahmad Shabibul Hossain, @shabib_hossain on 5/15/14.
Share feedbacks and ideas to improve this project, I would love to hear them out. You can also follow me on @shabib_hossain.
SHViewPager is available under the MIT license. See the LICENSE file for more info.