Latest 0.0.4
Homepage https://github.com/soapyigu/YGHorizontalScroller
License MIT
Platforms ios 8.0, requires ARC

Platform
Language
[CocoaPods]()

YGHorizontalScroller is a simple horizontal scroller implemented by Swift.

Requirements

  • iOS 8.0+
  • Xcode 6.0+

Instalation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate AutoLayoutPlus into your Xcode project using CocoaPods, include this in your Podfile:

platform :ios, '8.0'
use_frameworks!

pod 'YGHorizontalScroller'

Or just copy YGHorizontalScroller.swift into your project

Usage

YGHorizontalScroller works by wrapping sroller and UIViews together and offers a flexiable protocal with methods. To make use of methods don’t forget to import YGHorizontalScroller into your code:

import YGHorizontalScroller

Note: If you encounter an import error, building your project may resolve the problem

You can create the scroll view by:

scroller = YGHorizontalScroller(frame: CGRect(x: 0, y: 100, width: screenWidth, height: 300))
view.addSubview(scroller)

scroller.viewWidth = 200
scroller.viewHeight = 300
scroller.viewPadding = 10
scroller.viewOffset = 100

scroller.delegate = self
scroller.reload()

Then implement YGHorizontalScrollerDelegate protocol:

func numberOfViews(scroller: YGHorizontalScroller) -> Int {
  return images.count
}

func cellForViewAtIndex(scroller: YGHorizontalScroller, index: Int) -> UIView {
  let image = images[index]
  let imageView = UIImageView(image: image)

  if currentIndex == index {
    imageView.backgroundColor = UIColor.whiteColor()
  } else {
    imageView.backgroundColor = UIColor.blackColor()
  }

  return imageView
}

func didSelectViewAtIndex(scroller: YGHorizontalScroller, index: Int) {
  let previousView = scroller.viewAtIndex(currentIndex)
  previousView.backgroundColor = UIColor.blackColor()

  currentIndex = index

  let currentView = scroller.viewAtIndex(currentIndex)
  currentView.backgroundColor = UIColor.whiteColor
}

func initialViewIndex(scroller: YGHorizontalScroller) -> Int {
  return 0
}

Screenshots

portrait
landscape

Credits

Owned and maintained by Yi.

Contributing

Bug reports and pull requests are welcome.

License

YGHorizontalScroller is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "YGHorizontalScroller",
    "version": "0.0.4",
    "summary": "A Simple Horizontal Scroller implemented by Swift",
    "homepage": "https://github.com/soapyigu/YGHorizontalScroller",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": "Yi Gu",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/soapyigu/YGHorizontalScroller.git",
        "tag": "0.0.4"
    },
    "source_files": "YGHorizontalScroller/*.swift",
    "requires_arc": true
}

Pin It on Pinterest

Share This