-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
Hi,
Thanks for you repository. I need to add it to on of my viewController. I don't need it at AppDelegate.
This is my try:
class PagingViewController: SLPagingViewController {
override init(navBarItems items: [AnyObject]!, controllers: [AnyObject]!, showPageControl addPageControl: Bool) {
var orange = UIColor(red: 255/255, green: 69.0/255, blue: 0.0/255, alpha: 1.0)
var gray = UIColor(red: 0.84, green: 0.84, blue: 0.84, alpha: 1.0)
var ctr1 = UIViewController()
ctr1.title = "Ctr1"
ctr1.view.backgroundColor = orange
var ctr2 = UIViewController()
ctr2.title = "Ctr2"
ctr2.view.backgroundColor = UIColor.yellowColor()
var ctr3 = UIViewController()
ctr3.title = "Ctr3"
ctr3.view.backgroundColor = gray
var img1 = UIImage(named: "heart_selected")
img1 = img1?.imageWithRenderingMode(.AlwaysTemplate)
var img2 = UIImage(named: "people")
img2 = img2?.imageWithRenderingMode(.AlwaysTemplate)
var img3 = UIImage(named: "comment")
img3 = img3?.imageWithRenderingMode(.AlwaysTemplate)
var items = [UIImageView(image: img1), UIImageView(image: img2), UIImageView(image: img3)]
var controllers = [ctr1, ctr2, ctr3]
super.init(navBarItems: items, controllers: controllers, showPageControl: false)
self.pagingViewMoving = ({ subviews in
for v in subviews {
var lbl = v as! UIImageView
var c = gray
if(lbl.frame.origin.x > 45 && lbl.frame.origin.x < 145) {
c = self.gradient(Double(lbl.frame.origin.x), topX: Double(46), bottomX: Double(144), initC: orange, goal: gray)
}
else if (lbl.frame.origin.x > 145 && lbl.frame.origin.x < 245) {
c = self.gradient(Double(lbl.frame.origin.x), topX: Double(146), bottomX: Double(244), initC: gray, goal: orange)
}
else if(lbl.frame.origin.x == 145){
c = orange
}
lbl.tintColor = c
}
})
}
required init(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
}
func gradient(percent: Double, topX: Double, bottomX: Double, initC: UIColor, goal: UIColor) -> UIColor{
var t = (percent - bottomX) / (topX - bottomX)
let cgInit = CGColorGetComponents(initC.CGColor)
let cgGoal = CGColorGetComponents(goal.CGColor)
var r = cgInit[0] + CGFloat(t) * (cgGoal[0] - cgInit[0])
var g = cgInit[1] + CGFloat(t) * (cgGoal[1] - cgInit[1])
var b = cgInit[2] + CGFloat(t) * (cgGoal[2] - cgInit[2])
return UIColor(red: r, green: g, blue: b, alpha: 1.0)
}
}
Could you please guide me to the correct way to achieve it?!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels