Skip to content

A simple horizontal scroller framework implemented by Swift

License

Notifications You must be signed in to change notification settings

soapyigu/YGHorizontalScroller

Repository files navigation

YGHorizontalScroller

Platform Language CocoaPods

YGHorizontalScroller is a simple horizontal scroller implemented by Swift, this scroller will automatically center and highlight the subview you select or click.

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.

About

A simple horizontal scroller framework implemented by Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published