Ich habe eine Aufzählung Farben, um Farben zurückzugeben. Ich frage mich, ob Aufzählung die Änderungen der dynamischen Aplha erreichen kann.
enum Colors {
case
text,
yesColorWith(alpha:CGFloat)
var color: UIColor {
switch self {
case .text: return UIColorFromHEX(0xd1d1d1, alpha: 1.0)
case .yesColorWith(alpha: CGFloat) : return UIColorFromHEX(0x89A225, alpha: alpha)
}
}
}
func UIColorFromHEX(_ hex: UInt, alpha:Float) -> UIColor {
return UIColor(
red: CGFloat((hex >> 16) & 0xff) / 255,
green: CGFloat((hex >> 08) & 0xff) / 255,
blue: CGFloat((hex >> 00) & 0xff) / 255,
alpha: CGFloat(alpha))
}
Willkommen in der wilden und verrückten Welt der Swift- case
Muster. Veränderung
case .yesColorWith(alpha: CGFloat) :
zu
case .yesColorWith(let alpha) :
So:
enum Colors {
case text
case yesColorWith(alpha: CGFloat)
var color: UIColor {
switch self {
case .text:
return UIColorFromHEX(0xd1d1d1, alpha: 1.0)
case .yesColorWith(let alpha): // <-*
return UIColorFromHEX(0x89A225, alpha: alpha)
}
}
}
Dieser Artikel stammt aus dem Internet. Bitte geben Sie beim Nachdruck die Quelle an.
Bei Verstößen wenden Sie sich bitte [email protected] Löschen.
Lass mich ein paar Worte sagen