개발/TIL(Today I Learned)
Swift) Extension UIView
혜듀
2021. 9. 22. 02:54
// 뷰 변경 시 하이라이트를 줌 (확대 -> 축소)
// imageView.animateHighlight()
extension UIView {
func animateHighlight() {
UIView.animate(withDuration: 0.1, delay: 0, options: .curveEaseIn, animations: {
self.transform = CGAffineTransform(scaleX: 1.1, y: 1.1)
}, completion: { _ in
UIView.animate(withDuration: 0.1, delay: 0, options: .curveEaseOut, animations: {
self.transform = .identity
})
})
}
}
extension UIView {
func makeRound(masksToBounds: Bool = false) {
self.layer.cornerRadius = self.frame.height / 2
self.layer.cornerCurve = .continuous
self.layer.masksToBounds = masksToBounds
}
}
extension UIView {
func addShadow(with color: UIColor) {
self.layer.shadowOpacity = 0.5
self.layer.shadowColor = color.cgColor
self.layer.shadowRadius = 5
}
}