본문 바로가기
iOS

[iOS] 버튼 이미지가 표시되지 않는 이슈

by thoonk: 2022. 7. 11.

UIButton 이미지가 표시되지 않는 이슈 해결 방법을 기록합니다. 

 

UIButton의 setImage 메서드를 통해 버튼의 아이콘 이미지를 설정할 수 있지만

아이콘 포멧이 맞지 않으면, tintColor가 표시되게 됩니다.

 

해당 이미지를 아이콘 포멧 이미지에 맞게 바꾸어 주면 해당 이슈를 해결할 수 있습니다. 

또한, 해당 이미지를 original Image always로 렌더링하여 이슈를 해결 할 수 있고 이 방법을 아래 코드로 공유합니다. 

 

button.setImage(UIImage(named: "customImage")?.withRenderingMode(.alwaysOriginal), for: .normal)

 

부족한 점 피드백해주시면 감사합니다👍

 

Ref. 

https://www.dev2qa.com/how-to-fix-image-not-showing-error-for-swift-button/

 

How To Fix Image Not Showing Error For Swift Button

When you use UIKit.UIButton class’s setImage method to set swift button’s icon image, if the image is not icon format, it will display a purely blue color rectangle instead of the image. You can fix this error by converting the image to an icon format

www.dev2qa.com

'iOS' 카테고리의 다른 글

[iOS] Tag을 활용한 UIButton Action 처리  (0) 2022.10.28
[iOS] Custom Navigation Controller Pop Gesture Swift  (0) 2022.09.22
[iOS] WKWebView 정리 Swift  (0) 2022.02.04
[iOS] Unwind Segue  (1) 2021.11.11
[iOS] CaseIterable  (1) 2021.06.27

댓글