Open Maryom opened 9 years ago
Hello,
I think the point is to have it in the AppDelegate and then swap out the
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
Replace the UIViewController() with your view. What's the bigger picture of your app?
Yaroslaw Bagriy
Hi Yaroslaw Bagriy thanks for your reply. I need it in one of my viewcontrollers I know how to do it in Appdelegate, but I can't find a way to do it in one viewcontroller. Do you know a way to achieve it?
Hello,
Yes it is possible. So make a new class that subclasses UIViewController. Then make a storyboard UIViewController and set the class to the new UIViewController class you made.
In viewDidLoad add
var controller: SLPagingViewSwift!
var ctr1 = TestButtonViewController()
ctr1.title = "Ctr1"
var ctr2 = TestButtonViewController()
ctr2.title = "Ctr2"
var ctr3 = TestButtonViewController()
ctr3.title = "Ctr3"
var img1 = UIImage(named: "gear")
img1 = img1?.imageWithRenderingMode(.AlwaysTemplate)
var img2 = UIImage(named: "profile")
img2 = img2?.imageWithRenderingMode(.AlwaysTemplate)
var img3 = UIImage(named: "chat")
img3 = img3?.imageWithRenderingMode(.AlwaysTemplate)
var items = [UIImageView(image: img1), UIImageView(image: img2), UIImageView(image: img3)]
var controllers = [ctr1, ctr2, ctr3]
controller = SLPagingViewSwift(items: items, controllers: controllers, showPageControl: false)
controller.pagingViewMoving = ({ subviews in
for lbl in (subviews as! [UIImageView]) {
var c : UIColor!
switch (lbl.frame.origin.x) {
case 145:
c = orange
case 46 ... 144:
c = self.gradient(Double(lbl.frame.origin.x), topX: Double(46), bottomX: Double(144), initC: orange, goal: gray)
case 146 ... 244:
c = self.gradient(Double(lbl.frame.origin.x), topX: Double(146), bottomX: Double(244), initC: gray, goal: orange)
default:
c = gray
}
lbl.tintColor = c
}
})
self.presentviewcontroller(controller)
See if that works.
Yaroslaw Bagriy
Thanks again. First Swift version has many errors so I'm using objective c version. I tried your code I got two errors: 'SLPagingViewController' does not have a member named 'pagingViewMoving'
'TryViewController' does not have a member named 'presentviewcontroller'
var controller: SLPagingViewController! var ctr1 = Try0ViewController() ctr1.title = "Ctr1" var ctr2 = Try1ViewController() ctr2.title = "Ctr2" var ctr3 = Try2ViewController() ctr3.title = "Ctr3"
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]
controller = SLPagingViewController(navBarItems: items, controllers: controllers, showPageControl: false)
controller.pagingViewMoving = ({ subviews in
for lbl in (subviews as! [UIImageView]) {
var c : UIColor!
switch (lbl.frame.origin.x) {
case 145:
c = orange
case 46 ... 144:
c = self.gradient(Double(lbl.frame.origin.x), topX: Double(46), bottomX: Double(144), initC: orange, goal: gray)
case 146 ... 244:
c = self.gradient(Double(lbl.frame.origin.x), topX: Double(146), bottomX: Double(244), initC: gray, goal: orange)
default:
c = gray
}
lbl.tintColor = c
}
})
self.presentviewcontroller(controller)
Any idea how to solve it?
Opps wrong parameters for presentviewcontroller. try
self.presentViewController(controller, animated: false, completion: nil)
Yup I tried this but it doesn't work. So I used another repository and it works perfectly with me:
https://github.com/Tgy31/THTinderNavigationController
Thanks for your help.
I was able to get the swiping function to work but the issue that I'm facing is the header doesn't appear.
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 {
}
Could you please guide me to the correct way to achieve it?!