[ios_Swift] Button 내 텍스트와 이미지 여백 추가하기

이시영·2023년 11월 2일

버튼 내에서도 텍스트나 이미지에 패팅값을 줄 수 있는 방법이 있는데 아래 메써드를 사용해주면 된다.

button.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
button.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

단 contentEdgeInsets 은 버튼 크기제약에는 영향을 주지 않기때문에 콘텐츠가 버튼을 벗어날 수도 있다.

0개의 댓글