Mam numer UIButton
i utworzyłem rozszerzenie, aby dodać kolor tła dla innego stanu.Kolor tła UIButton dla podświetlonego/wybranego stanu wydania
używam następujący kod:
extension UIButton {
func setBackgroundColor(color: UIColor, forState: UIControlState) {
UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), color.CGColor)
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRect(x: 0, y: 0, width: 1, height: 1))
let colorImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.setBackgroundImage(colorImage, forState: forState)
}
}
// Set Button Title and background color for different states
self.donateButton.setBackgroundColor(UIColor.redColor(), forState: .Normal)
self.donateButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
self.donateButton.setBackgroundColor(UIColor.greenColor(), forState: .Highlighted)
self.donateButton.setTitleColor(UIColor.whiteColor(), forState: .Highlighted)
self.donateButton.setBackgroundColor(UIColor.greenColor(), forState: .Selected)
self.donateButton.setTitleColor(UIColor.whiteColor(), forState: .Selected)
Moim problemem jest to, że nie odbiera prawidłowego
UIButton
kolor tła i napisów kolor podświetlonego/wybranego państwa.
Miałem ten sam problem, co sprawiło, że niestandardowy zrobił lewy. Stan wciśnięty jest wyróżniony zamiast tego, co myślałem (wybrano): S. – MQoder