UIButton의 Autolayout이 titleEdgeInsets를 고려하지 않았기 때문에 대응했습니다.
3724 단어 AutoLayoutiOSUIKitSwift
편리하게 하고 싶은 점
InterfaceBuilder의 UIButton에 titleEdgeInsets를 설정하고,
버튼의 문장만을 프로그램상에서 설정(변경)하면 문장의 길이에 따라
버튼의 크기가 변경되지만 그 크기에 titleEdgeInsets가 반영되지 않기 때문에
표시가 무너져 버린다.

맞지 않는다.
타이틀을 변경한 것을 Autolayout에 명시적으로 통지할 필요가 있을까 생각하고,
다음 코드를 실행해 보았습니다.
botton.setTitle("収めて収めて収めて収めて収めて", forState: .Normal)
// AutolayoutにintrinsicContentSizeが変更された事を伝える
button.invalidateIntrinsicContentSize()

맞지 않는다.
대응
조사해 본 결과 intrinsicContentSize가 원래 titleEdgeInsets를 고려하지 않았다는 것이 밝혀졌기 때문에 다음과 같은 UIButton의 extension을 구현
extension UIButton {
public override func intrinsicContentSize() -> CGSize {
let originalContentSize = super.intrinsicContentSize()
let adjustedWidth = originalContentSize.width + titleEdgeInsets.left + titleEdgeInsets.right
let adjustedHeight = originalContentSize.width + titleEdgeInsets.top + titleEdgeInsets.bottom
return CGSize(width: adjustedWidth, height: adjustedHeight)
}
}
반환값의 CGSize에 대해서 각각, edgeInsets의 값을 더해 준다.
그러면·····

맞았어.
감상
약간의 신경 쓰지 않는 부분에 찢어졌습니다 
UIButton에는 이것과는 별도로 imageEdgeInsets도 존재하고 있기 때문에, imageEdgeInsets로 어색한 분은 같은 순서로 개선될까 생각합니다.
Reference
이 문제에 관하여(UIButton의 Autolayout이 titleEdgeInsets를 고려하지 않았기 때문에 대응했습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/takashi9314/items/14c183c6d4f233253ee3
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
botton.setTitle("収めて収めて収めて収めて収めて", forState: .Normal)
// AutolayoutにintrinsicContentSizeが変更された事を伝える
button.invalidateIntrinsicContentSize()
조사해 본 결과 intrinsicContentSize가 원래 titleEdgeInsets를 고려하지 않았다는 것이 밝혀졌기 때문에 다음과 같은 UIButton의 extension을 구현
extension UIButton {
public override func intrinsicContentSize() -> CGSize {
let originalContentSize = super.intrinsicContentSize()
let adjustedWidth = originalContentSize.width + titleEdgeInsets.left + titleEdgeInsets.right
let adjustedHeight = originalContentSize.width + titleEdgeInsets.top + titleEdgeInsets.bottom
return CGSize(width: adjustedWidth, height: adjustedHeight)
}
}
반환값의 CGSize에 대해서 각각, edgeInsets의 값을 더해 준다.
그러면·····

맞았어.
감상
약간의 신경 쓰지 않는 부분에 찢어졌습니다 
UIButton에는 이것과는 별도로 imageEdgeInsets도 존재하고 있기 때문에, imageEdgeInsets로 어색한 분은 같은 순서로 개선될까 생각합니다.
Reference
이 문제에 관하여(UIButton의 Autolayout이 titleEdgeInsets를 고려하지 않았기 때문에 대응했습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/takashi9314/items/14c183c6d4f233253ee3
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(UIButton의 Autolayout이 titleEdgeInsets를 고려하지 않았기 때문에 대응했습니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/takashi9314/items/14c183c6d4f233253ee3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)