A news ticker view written entirely in swift
SwiftTickerView
I'll definately have to update this gif, it doesn't look that crappy anymore!
Customize the Renderer easily by adding a new decorators:
```Renderer.topToBottom.customize(with: SwiftTickerItemDecorators.prepareAtBottomInnerBorder(with: 8))```
Following new Render decorators are vailable:
* ```prepareAtTopInnerBorder()```
* ```prepareAtTopOuterBorder()```
* ```prepareAtBottomInnerBorder()```
* ```prepareAtBottomOuterBorder()```
* ```prepareAtLeftInnerBorder()```
* ```prepareAtLeftOuterBorder()```
* ```prepareAtRightInnerBorder()```
* ```prepareAtRightOuterBorder()```
Implement your own inital or update Render decorator by implementing the InitialRenderer & SwiftTickerItemDecorator
or UpdateRenderer & SwiftTickerItemDecorator
Following new Ticker decorator is available:
ignoreFirstSeparator
Add a decorator to the TickerView by callingtickerView.add(.ignoreFirstSeparator)
Renamings
SwiftTickerView.Renderer.rightToLeft
renamed toRenderer.rightToLeft
SwiftTickerView.Renderer.leftToRight
renamed toRenderer.leftToRight
SwiftTickerView.Renderer.topToBottom
renamed toRenderer.topToBottom
SwiftTickerView.Renderer.bottomToTop
renamed toRenderer.bottomToTop
1.3.0
- You can now implement your own renderer
Renamings
- renamed
direction
torenderer
Direction.horizontalRightToLeft
renamed toSwiftTickerView.Renderer.rightToLeft
Direction.horizontalLeftToRight
renamed toSwiftTickerView.Renderer.leftToRight
Direction.verticalTopToBottom
renamed toSwiftTickerView.Renderer.topToBottom
Direction.verticalBottomToTop
renamed toSwiftTickerView.Renderer.bottomToTop
1.2.2
- Now supports TV OS
- Performance improvements
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
SwiftTickerView is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'SwiftTickerView'
Setup
You can eigther embed the SwiftTickerView within an Storyboard or a Xib View, or instantiate the View just like any other view:
let tickerView = SwiftTickerView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 30))
Use the separator property to simply create those textual separators or set a separator view class or nib to create those separator views. Also implement the viewProvider protocol to manipulate the separator view and the node view on demand
tickerView.separator = "+++"
tickerView.viewProvider = self
...
Register also some custom node views to be able to load them more easily
tickerView.registerNodeView(UILabel.self, for: labelIdentifier)
If you want some callbacks on if the user stopped the ticker view (yes, the user can stop the view by tapping on the ticker view), implement the tickerDelegate and don't forget to asign it to the ticker view. You will also be able to determine the content, which the user has selected.
tickerView.tickerDelegate = self
This ticker view is designed to be able to support arabic and hebrew aswell as the other languages. Simply use the direction property, to determine if you want the content to run from left to right, from right to left, from top to bottom or from bottom to top:
tickerView.renderer = SwiftTickerView.Renderer.rightToLeft
You can manage the velocity of the content to run across the display. You can alter this value at runtime aswell to increase or slow down the ticker view:
tickerView.pixelPerSecond = 60 //default is 60
Don't forget to start the tickerview, otherwhise it's not working:
tickerView.start()
And last but not least, implement the contentProvider property to provide your content!
Btw, in the viewProvider protocol, the view node view creation function has to return a tuple with a view parameter and an optional reuseIdentifier parameter. Use this parameter to store it and reuse it for later usage:
func tickerView(_ tickerView: SwiftTickerView, viewFor: Any) -> (UIView, reuseIdentifier: String?) {
if let text = viewFor as? String,
let label = tickerView.dequeReusableNodeView(for: labelIdentifier) as? UILabel {
label.text = text
label.sizeToFit()
label.textColor = .white
return (label, reuseIdentifier: labelIdentifier)
}
return (UIView(), reuseIdentifier: nil)
}
func tickerView(_ tickerView: SwiftTickerView, prepareSeparator separator: UIView) {
if let separator = separator as? UILabel {
separator.textColor = .white
}
}