Skip to content

Instantly share code, notes, and snippets.

@johndpope
Created May 18, 2017 14:34
Show Gist options
  • Save johndpope/5eef5fab18ad20b467b8da81032fa83f to your computer and use it in GitHub Desktop.
Save johndpope/5eef5fab18ad20b467b8da81032fa83f to your computer and use it in GitHub Desktop.
import Foundation
import SnapKit
import Material
import Dotzu
import TweenKit
class RotatingTextLabel: UIView {
private let label: UILabel = UILabel()
fileprivate var labelXoffset:CGFloat = 16
override init(frame: CGRect) {
super.init(frame: frame)
self.setup()
}
convenience init() {
self.init(frame: .zero)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setup()
}
func setup() {
self.backgroundColor = .yellow
self.addSubview(self.label)
self.label.snp.remakeConstraints { (make) -> Void in
make.top.width.height.equalToSuperview()
make.left.equalToSuperview().offset(labelXoffset)
}
label.font = RobotoFont.medium(with: 15)
label.textColor = .white
label.backgroundColor = .red
}
//MARK: - Public functions
func setText(text: String?) {
self.label.text = text
self.startRotating()
}
func startRotating() {
UIView.animate(
withDuration:5.0,
delay: 0.0,
options: [UIViewAnimationOptions.curveLinear, UIViewAnimationOptions.beginFromCurrentState, UIViewAnimationOptions.repeat],
animations: {
self.labelXoffset = 45
self.label.snp.updateConstraints { (make) -> Void in
make.left.equalTo(self.labelXoffset)
}
},
completion: { _ in
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment