ios - Animate UILabel text color in Swift -
how can animate color change of uilabel using swift? have seen people mention using calayer cannot figure out swift syntax.
this example of objective-c
calayer *layer = myview.layer; catextlayer *textlayer = [catextlayer layer]; [textlayer setstring:@"my string"]; [textlayer setforegroundcolor:initialcolor; [textlayer setframe:self.bounds]; [[self.view layer] addsublayer:textlayer]; [uiview animatewithduration:0.5 animations:^{ textlayer.foregroundcolor = finalcolor; }];
it easier working calayer
let mylabel: uilabel! uiview.animatewithduration(2, animations: { () -> void in mylabel.backgroundcolor = uicolor.redcolor(); })
thats it...
edit
ok, sorry didn't knew color want change... have converted example swift code...
first
import quartzcore
than
if let layer: calayer = self.view.layer calayer? { if let textlayer = catextlayer() catextlayer? { textlayer.string = "my string" textlayer.foregroundcolor = uicolor.whitecolor().cgcolor textlayer.frame = self.view.bounds self.view.layer.addsublayer(textlayer) uiview.animatewithduration(0.5, animations: { () -> void in textlayer.foregroundcolor = uicolor.redcolor().cgcolor }) } }
Comments
Post a Comment