Swiftgram/submodules/GraphUI/Sources/UILabel+Utils.swift
2020-03-12 05:01:21 +04:00

38 lines
1.1 KiB
Swift

//
// UILabel+Utils.swift
// GraphTest
//
// Created by Andrei Salavei on 4/9/19.
// Copyright © 2019 Andrei Salavei. All rights reserved.
//
import UIKit
extension UILabel {
func setTextColor(_ color: UIColor, animated: Bool) {
if self.textColor != color {
if animated {
let animation = CATransition()
animation.timingFunction = CAMediaTimingFunction.init(name: .linear)
animation.type = .fade
animation.duration = .defaultDuration
self.layer.add(animation, forKey: "kCATransitionColorFade")
}
self.textColor = color
}
}
func setText(_ title: String?, animated: Bool) {
if self.text != title {
if animated {
let animation = CATransition()
animation.timingFunction = CAMediaTimingFunction.init(name: .linear)
animation.type = .fade
animation.duration = .defaultDuration
self.layer.add(animation, forKey: "kCATransitionTextFade")
}
self.text = title
}
}
}