Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rotate png inside uibutton

I have a UIButton inside a titleView of a UINavigationBar. I want to rotate a downwards caret image 180 degrees every time the user taps a given button.

enter image description here

like image 762
luke Avatar asked Oct 16 '25 13:10

luke


1 Answers

Here's an example of how can you do it using Transforms:- The code works with all the elements that inherits from UIView

UIView.animate(withDuration: 0.5) {
            self.yourButton.imageView?.transform = CGAffineTransform(rotationAngle: CGFloat.pi)

}

To set it back to original position:-

UIView.animate(withDuration: 0.5) {
      self.yourButton.imageView?.transform = .identity)

}
like image 153
Dark Innocence Avatar answered Oct 19 '25 03:10

Dark Innocence