Search code examples
iosswiftanimationsplash-screenfade

How to make a text to fade out and only get some letters and create a new word in swift?


I am trying to make a launch splash screen for my iOS project. I want to show my service full name and then just get the first letters of each word with the other words getting faded away.

For example

Service Involvement Expenditure - > Intially

S I E -> Letters to be displayed after other texts fade away.

Splash Screen

Please help me to make something like the above gif ?


Solution

  • You have to split the text and then fetch the first character of each substring just like that

    var YourString: String = "Service Involvement Expenditure"
    let sunstringArray = YourString.componentsSeparatedByString(" ")
    
    var firstString: String = sunstringArray [0]    //Service 
    var secondString: String = sunstringArray [1]   //Involvement 
    var thirdString: String = sunstringArray [2]    //Expenditure
    

    now to get only the first charcter use below code

     var firstletter = String(firstString.characters.first!)    //S
      var secondletter = String(secondString.characters.first!)    //I
      var thirdletter = String(thirdString.characters.first!)    //E
    
    var fullFirstChar = firstletter + secondletter + thirdletter //SIE
    
     UIView.animate(withDuration: 2.0, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: {
                                self.fullFirstChar .alpha = 1.0
                            },
                                           completion: {
    
                                            (finished: Bool) -> Void in
    
                                        // Fade out
                                        UIView.animate(withDuration: 2.0, delay: 0.0, options: UIViewAnimationOptions.curveEaseIn, animations: {
                                            self.fullFirstChar .alpha = 0.0
                                        },
                                                       completion: {(finished: Bool) -> Void in
                                                        AppInfo.instance.isAnimationCompleted = true
                                        })
                        })
    

    i hope this will help