UIButton 제목 정렬 및 여러 줄 지원
의 제목을 UIButton
왼쪽 정렬로 설정하는 방법과 여러 줄의 텍스트를 어떻게 표시 할 수 UIButton
있습니까?
코드에서 UIButton 정렬을 수행하는 코드도 다음과 같습니다.-
[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
의 정렬을 설정하려면UIButton
Interface Builder의 Attributes Inspector에서 버튼을 찾으십시오. Alignment라는 섹션이 있습니다. 왼쪽으로 설정합니다. 아니면 당신이 원하는대로.
코드에서 작업을 수행하려면 사용 contentHorizontalAlignment
의 속성을 UIControl
. 다음 속성 중 하나로 설정할 수 있습니다.
UIControlContentHorizontalAlignmentCenter
UIControlContentHorizontalAlignmentLeft
UIControlContentHorizontalAlignmentRight
UIControlContentHorizontalAlignmentFill
[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
이러한 옵션 중 어느 것도 특별히 좋아 보이지는 않으며 (위에서 볼 수 있듯이) 콘텐츠 위치를 변경하기 위해 의 contentEdgeInsets
속성을 사용하는 데 더 많은 행운이있을 수 있습니다 UIButton
.
여러 줄의 제목을 설정하려면 A의를 UIButton
, 이 포럼 게시물 확인 버튼 레이블 변경에 대해 설명합니다.
또는이 코드를 사용하여 2 줄 버튼을 빠르게 만들 수 있습니다.
myButton.titleLabel.textAlignment = UITextAlignmentCenter;
myButton.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
[myButton setTitle:@"Siegfried\nRoy" forState:UIControlStateNormal];
Raju, 질문을 수락 된 것으로 표시하는 것을 잊지 마십시오.
실제로 lineBreakMode
를 UILineBreakModeWordWrap
또는로 설정할 수 있습니다 UILineBreakModeCharacterWrap
. 필요한 경우 텍스트를 여러 줄로 나눕니다.
이 시도
myButton.titleLabel.textAlignment = UITextAlignmentLeft;
myButton.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
myButton.titleLabel.numberOfLines = 0;
단락 효과를 추가하려면 제목의 크기를 변경할 수 있습니다.
참고 URL : https://stackoverflow.com/questions/954589/uibutton-title-alignment-and-multiline-support
'Programing' 카테고리의 다른 글
Date 개체에 요일 추가 (0) | 2020.11.06 |
---|---|
업로드되는 dropzone.js 파일 수를 제한하는 방법은 무엇입니까? (0) | 2020.11.06 |
django / python에서 이메일의 유효성 확인 (0) | 2020.11.06 |
목록을 얻는 방법 (0) | 2020.11.06 |
XOR 변수 스와핑은 어떻게 작동합니까? (0) | 2020.11.06 |