Raj*_*aju 68 iphone cocoa-touch uibutton uikit ios
如何将a的标题设置UIButton为左对齐,如何在a中显示多行文本UIButton?
Ian*_*haw 187
以下是在代码中执行UIButton对齐的代码: -
[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
Run Code Online (Sandbox Code Playgroud)
nev*_*ing 131
要设置a的对齐方式UIButton,请在Interface Builder的Attributes Inspector中查找按钮.有一个名为Alignment的部分.将其设置为左侧.或者对,或者你想要什么.

要在代码中执行此操作,请使用contentHorizontalAlignment属性UIControl.您可以将其设置为以下任何属性:
UIControlContentHorizontalAlignmentCenter
UIControlContentHorizontalAlignmentLeft
UIControlContentHorizontalAlignmentRight
UIControlContentHorizontalAlignmentFill
[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
Run Code Online (Sandbox Code Playgroud)
这些选项中没有一个看起来特别好(正如您在上面看到的那样),并且您可能有更多运气使用contentEdgeInsets属性UIButton来重新定位内容.
要在a上设置多行标题UIButton,请查看此论坛帖子,其中介绍了如何更改按钮标签.
或者您可以使用此代码快速制作2行按钮:
myButton.titleLabel.textAlignment = UITextAlignmentCenter;
myButton.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
[myButton setTitle:@"Siegfried\nRoy" forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)

Raju,不要忘记将问题标记为已接受.
实际上,您可以设置lineBreakMode为UILineBreakModeWordWrap或UILineBreakModeCharacterWrap.如有必要,这会将文本分成多行.
试试这个
myButton.titleLabel.textAlignment = UITextAlignmentLeft;
myButton.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
myButton.titleLabel.numberOfLines = 0;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45218 次 |
| 最近记录: |