Skip to content

sarn/ARNRouletteWheelView

Repository files navigation

ARNRouletteWheelView

Version License Platform

Overview

A custom UICollectionView layout which resembles a spinning roulette wheel. The cells are laid out on an invisible wheel and the wheel spins by scrolling horizontally.

This custom layout is based on the article by Rounak Jain. Thanks for the awesome article and work. The article is available here: http://www.raywenderlich.com/107687/uicollectionview-custom-layout-tutorial-spinning-wheel

Usage

Add the ARNRouletteWheelView to your UIViewController, overwrite the default cell with your custom ARNRouletteWheelCell subclass and optionally tweak the settings like wheel radius, the spacing between items and the size of the items.

To have a full screen ARNRouletteWheelView:

ARNRouletteWheelView *rouletteWheelView = [[ARNRouletteWheelView alloc] initWithFrame:self.view.frame];
rouletteWheelView.dataSource = self;

// overwrite default cell with a custom subcell
[rouletteWheelView registerClass:[ARNPosterCell class] forCellWithReuseIdentifier:@"ARNPosterCell"];

// custom settings
// [rouletteWheelView setRadius:2000.0f];
// [rouletteWheelView setInterItemSpacing:1.5f];
// [rouletteWheelView setItemSize:CGSizeMake(100.0f, 100.0f)];

[self.view addSubview:rouletteWheelView];

Your custom ARNRouletteWheelCell subclass could look like this:

@interface ARNPosterCell ()
@property (nonatomic, strong) UIImageView *imageView;
@end

@implementation ARNPosterCell

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _imageView.clipsToBounds = YES;
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:_imageView];
    }
    return self;
}

- (void)setImage:(UIImage *)image {
    if (image != nil) {
        [self.imageView setImage:image];
    }
}
@end

Example Project

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • ARC
  • iOS7

Installation

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

pod "ARNRouletteWheelView"

Author

Stefan Arn

License

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

About

A roulette wheel like custom UICollectionView layout

Resources

License

Stars

Watchers

Forks

Packages

No packages published