iOS/Swift

[iOS] Swift 라이브러리 typing animation

🥭Mango 2021. 8. 23. 16:50

첫번째 방법

단순 코드로 구현하는 방법이다. 

import UIKit

class WelcomeViewController: UIViewController {

    @IBOutlet weak var titleLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        titleLabel.text = ""
        var charIndex = 0.0
        let titleText = "⚡️FlashChat"
        for letter in titleText {
            Timer.scheduledTimer(withTimeInterval: 0.1 * charIndex, repeats: false) { timer in
                self.titleLabel.text?.append(letter)
            }
            charIndex += 1
        }
       
    }

}

 

두번째 방법

CocoaPods를 이용하는 방법이다.

 

cocoapod 설치방법

//step 1
sudo gem install cocoapods

//step 2
pod setup --verbose

//설치되었는지 확인
pod --version
//step 1 작업중인 디렉토리로 이동
cd 본인이 작업중인 디렉토리 경로  //예시 : cd /Users/gildong/ios/example

//step 2
pod init

//step 3
podfile을 xcode로 열어준다.

<열린 podfile>

<수정된 podfile>

platform :ios, '9.0'

target 'Flash Chat iOS13' do
  use_frameworks!

  # Pods for Flash Chat iOS13
  
    pod 'CLTypingLabel' 
    
end

사이트에 나와있듯 pod 'CLTypingLabel' 을 추가해준다. 

 

pod install

흰색 xcworkspace 파일이 만들어지는데 이걸로 들어간다.