iOS, Swift
Swift ) .system타입 UIButton setTitle 애니메이션 없애기 - EEYatHo iOS
EEYatHo
2021. 3. 22. 16:14
var myButton = UIButton(type: .system)
...
myButton.setTitle("text", for: .normal)
...
myButton.setTitle("text2", for: .normal)
위와 같이 .system 타입으로 선언한 버튼에, 두번째 setTitle을 하게 되면,
버튼의 텍스트들이 천천히 사라졌다가 나타나는 애니메이션이 적용됩니다.
이런 애니메이션을 원하지 않을 경우,
var myButton = UIButton(type: .system)
...
myButton.setTitle("text", for: .normal)
...
UIView.setAnimationsEnabled(false)
myButton.setTitle("text2", for: .normal)
myButton.layoutIfNeeded()
UIView.setAnimationsEnabled(true)
두번째 setTitle을 애니메이션을 막고, layoutIfNeeded()를 호출하면 됩니다.
반응형