Skip to main content

UILabel text animation as in UIButton click


Animating UILabel textcolor is not easy as it seems, normal animation won't work on this property. The below code snippet animates the UILabel textcolor as in button click.
Change the duration and UIViewAnimationOptions to play with it.
extension UILabel{
    func flashLabel() {
        func animate(duration:Double,alpha:CGFloat,completion:(()->())?){
            UIView.transition(with: self, duration: duration, options: UIViewAnimationOptions.transitionCrossDissolve, animations: {
                self.textColor = self.textColor?.withAlphaComponent(alpha)
            }) { _ in
                completion?()
            }
        }
        animate(duration: 0.1, alpha: 0) {
            animate(duration: 0.3, alpha: 1, completion: nil)
        }
    }
}
Happy coding...

Comments

Popular posts from this blog

Design Patterns in Swift

What is a Design pattern?
A design pattern is a general solution to a real-world problem that can be re-used.
Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system.
They are templates designed to help us write efficient code which is easy to understand, also can be re-used.
It is not a finished design that can be transformed directly into source or machine code.

Why do we need Design patterns?
Saves Time: Design patterns can speed up the development process by providing tested, proven development paradigmsFuture bugs: Effective design pattern can solve issues that may not become visible until later in the implementation, which helps while designing software.Re-use: Reusing design patterns helps to prevent subtle issues that can cause major problems.Code Readability: Improves code readability for coders and architects familiar with the patterns. Best practices: Design patterns teaches us some of the best pra…

Stack Problem - Balancing of Symbols

Stack Problem - Balancing of Symbols
Problem: Given an expression string exp , write a program to examine whether the pairs and the orders of “{“,”}”,”(“,”)”,”[“,”]” are correct in exp.

Example:
Input: exp = “[()]{}{[()()]()}”
Output: Balanced Input: exp = “[(])”
Output: Not Balanced
Algorithm:
Create a stack.while ( end of input is not reached ) {If the character read is not a symbol to be balanced, ignore it.If the character is an opening delimiter like ( , {  or [ , PUSH it into the stack.If it is a closing symbol like ) , } , ] , then if the stack is empty report an error, otherwise POP the stack.If the symbol POP-ed is not the corresponding delimiter, report an error.At the end of the input, if the stack is not empty report an error.Implementation :
func balancingOfSymbols(string:String)->Bool{ guard string.count > 0else { return false } let symbols:[Character:Character] = ["{":"}","[":"]","(":")",] v…