https://github.com/soapyigu/yghorizontalscroller
A simple horizontal scroller framework implemented by Swift
https://github.com/soapyigu/yghorizontalscroller
Last synced: about 1 year ago
JSON representation
A simple horizontal scroller framework implemented by Swift
- Host: GitHub
- URL: https://github.com/soapyigu/yghorizontalscroller
- Owner: soapyigu
- License: mit
- Created: 2016-05-10T03:29:46.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-16T15:53:23.000Z (about 10 years ago)
- Last Synced: 2025-04-22T12:35:57.641Z (about 1 year ago)
- Language: Swift
- Size: 12.3 MB
- Stars: 36
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# YGHorizontalScroller
[](https://developer.apple.com/iphone/index.action)
[](https://developer.apple.com/swift)
[]()
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](https://cocoapods.org/) is a dependency manager for Cocoa projects. You can install it with the following command:
```bash
$ gem install cocoapods
```
To integrate AutoLayoutPlus into your Xcode project using CocoaPods, include this in your Podfile:
```ruby
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:
```swift
import YGHorizontalScroller
```
**Note: If you encounter an import error, building your project may resolve the problem**
You can create the scroll view by:
```swift
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:
```swift
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


## 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.