Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to animate UILabel's textcolor change? [duplicate]

 UIView.animateWithDuration(5, animations: {
        myLabel.textColor = UIColor.redColor()
    })

Label textcolor just changes instantly

like image 865
mres Avatar asked Dec 20 '14 05:12

mres


2 Answers

Try this

[UIView transitionWithView:myLabel duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
    label.textColor = [UIColor redColor];
} completion:^(BOOL finished) {
}];
like image 149
Nikita Khandelwal Avatar answered Oct 05 '22 03:10

Nikita Khandelwal


I write down the code for Objective-C and Swift

animation types

typedef NS_OPTIONS(NSUInteger, UIViewAnimationOptions) {
UIViewAnimationOptionCurveEaseInOut            = 0 << 16, // default
UIViewAnimationOptionCurveEaseIn               = 1 << 16,
UIViewAnimationOptionCurveEaseOut              = 2 << 16,
UIViewAnimationOptionCurveLinear               = 3 << 16,

UIViewAnimationOptionTransitionNone            = 0 << 20, // default
UIViewAnimationOptionTransitionFlipFromLeft    = 1 << 20,
UIViewAnimationOptionTransitionFlipFromRight   = 2 << 20,
UIViewAnimationOptionTransitionCurlUp          = 3 << 20,
UIViewAnimationOptionTransitionCurlDown        = 4 << 20,
UIViewAnimationOptionTransitionCrossDissolve   = 5 << 20,
UIViewAnimationOptionTransitionFlipFromTop     = 6 << 20,
UIViewAnimationOptionTransitionFlipFromBottom  = 7 << 20,
} NS_ENUM_AVAILABLE_IOS(4_0);

coding for Objective-C

[UIView transitionWithView:myLabel duration:0.20 options: UIViewAnimationOptionTransitionFlipFromBottom animations:^{
myLabel.textColor = [UIColor redColor];

} completion:^(BOOL finished) {
}];

coding for Swift

  UIView.transition(with: myLabel, duration: 0.20, options: .transitionFlipFromBottom, animations: {() -> Void in
        self.myLabel.textColor = UIColor.red
    }, completion: {(_ finished: Bool) -> Void in
    })
like image 45
Anbu.Karthik Avatar answered Oct 05 '22 02:10

Anbu.Karthik