如何在Swift中的UISegmentedcontrol中设置单个段颜色?

时间:2015-05-04 18:57:01

标签: ios uisegmentedcontrol

    // 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")
    }
}

0 个答案:

没有答案