Latest 0.3.1
Homepage https://github.com/Elethom/PRSlideView
License MIT
Platforms ios 5, requires ARC
Authors

CocoaPods
Language
License

Tweet
Twitter

Slide view with gracefully written UIKit-like methods, delegate and data source protocol.

Note: Auto layout not supported due to the special behaviours of UIScrollView. Please use autoresizing mask instead or wrap it with a container view.

Features

  • Horizontal or vertical scrolling
  • Infinite scrolling
  • Page control (horizontal mode only)

Installation

With CocoaPods

In your Podfile:

pod 'PRSlideView'

Usage

Create a Slide View

PRSlideView *slideView = [[PRSlideView alloc] initWithFrame:self.view.bounds];
slideView.delegate = self;
slideView.dataSource = self;
slideView.direction = PRSlideViewDirectionHorizontal; // horizontal by default
slideView.infiniteScrollingEnabled = YES; // disabled by default
slideView.showsPageControl = YES; // enabled by default
[slideView registerClass:PRAlbumPage.class
  forPageReuseIdentifier:NSStringFromClass(PRAlbumPage.class)];
slideView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
                              UIViewAutoresizingFlexibleHeight);
self.slideView = slideView;
[self.view addSubview:slideView];

Create a Slide View Page Subclass

#import "PRSlideViewPage.h"

@interface PRAlbumPage : PRSlideViewPage

@property (nonatomic, weak) UIImageView *coverImageView;

@end
#import "PRAlbumPage.h"

@implementation PRAlbumPage

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *coverImageView = [[UIImageView alloc] initWithFrame:self.bounds];
        coverImageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
                                           UIViewAutoresizingFlexibleHeight);
        coverImageView.contentMode = UIViewContentModeScaleAspectFit;
        self.coverImageView = coverImageView;
        [self addSubview:coverImageView];
    }
    return self;
}

Use Data Source

#pragma mark - PRSlideViewDataSource

- (NSInteger)numberOfPagesInSlideView:(PRSlideView *)slideView
{
    return self.albumData.count;
}

- (PRSlideViewPage *)slideView:(PRSlideView *)slideView pageAtIndex:(NSInteger)index
{
    PRAlbumPage *page = [slideView dequeueReusablePageWithIdentifier:NSStringFromClass(PRAlbumPage.class)
                                                            forIndex:index];

    NSString *imageName = [self.albumData[index] stringByAppendingPathExtension:@"jpg"];
    page.coverImageView.image = [UIImage imageNamed:imageName];

    return page;
}

Use Delegate

#pragma mark - PRSlideViewDelegate

- (void)slideView:(PRSlideView *)slideView didScrollToPageAtIndex:(NSInteger)index
{
    self.titleLabel.text = self.albumData[index];
}

- (void)slideView:(PRSlideView *)slideView didClickPageAtIndex:(NSInteger)index
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You clicked an album"
                                                    message:self.albumData[index]
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}

All done! You can check out the code in the demo provided.

License

This code is distributed under the terms and conditions of the MIT license.

Donate

You can support me by:

:-)

Contact

Latest podspec

{
    "name": "PRSlideView",
    "version": "0.3.1",
    "summary": "Slide view with UIKit-like methods, delegate and data source protocol.",
    "homepage": "https://github.com/Elethom/PRSlideView",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Elethom Hunter": "[email protected]"
    },
    "social_media_url": "https://twitter.com/ElethomHunter",
    "platforms": {
        "ios": 5
    },
    "source": {
        "git": "https://github.com/Elethom/PRSlideView.git",
        "tag": "0.3.1"
    },
    "source_files": "Classes/*.{h,m}",
    "public_header_files": "Classes/*.h",
    "requires_arc": true
}

Pin It on Pinterest

Share This