반응형
How to change Button Title Alignment in Swift?
I am trying to set the title on a Button to left. But everything i tried is not working.
With:
UILabelButton.titleLabel.textAlignment = .Left
Or:
UILabelButton.contentVerticalAlignment = UIControlContentVerticalAlignment // There is no left
The button title is still centered.
Is there another Property?
Use contentHorizontalAlignment
.You have to use UIControlContentHorizontalAlignment.Left
.You need to usehorizontal
not vertical
.
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
Swift 3.x
btn.contentHorizontalAlignment = .left
Swift 4
Sample code
For my requirement I want alignment left top
btnAddress.contentHorizontalAlignment = UIControlContentHorizontalAlignment.left
btnAddress.contentVerticalAlignment = UIControlContentVerticalAlignment.top
Swift 5 update:
btnAddress.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.left
btnAddress.contentVerticalAlignment = UIControl.ContentVerticalAlignment.top
like this with swift 4: btnAddress.contentHorizontalAlignment = .center
ReferenceURL : https://stackoverflow.com/questions/25005659/how-to-change-button-title-alignment-in-swift
반응형
'Development Tip' 카테고리의 다른 글
URL에서 반환 된 Zip 파일 다운로드 (0) | 2021.01.09 |
---|---|
while (1)의 목적; (0) | 2021.01.09 |
그림자를 어떻게 렌더링합니까? (0) | 2021.01.09 |
캐시를 사용하지 않는 Curl 명령 (0) | 2021.01.09 |
온라인 PHP IDE가 있습니까? (0) | 2021.01.09 |