// Add target action method
recipientSegmentedControl.addTarget(self, action: "changeColor:", forControlEvents: .ValueChanged)
// Add this custom segmented control to the view
self.view.addSubview(recipientSegmentedControl)
}
func changeColor(sender: UISegmentedControl) {
println("Change color handler is called.")
print("Changing Color to ")
switch sender.selectedSegmentIndex {
case 1:
self.recipientSegmentedControl.tintColor = UIColor.greenColor()
println("Green")
case 2:
self.recipientSegmentedControl.tintColor = UIColor.blueColor()
println("Blue")
default:
self.recipientSegmentedControl.tintColor = UIColor.purpleColor()
println("Purple")
}
}