繁体   English   中英

UIButton标题对齐和多行支持

[英]UIButton title alignment and multiline support

如何将UIButton的标题设置为左对齐,以及如何在UIButton显示多行文本?

这也是在代码中进行UIButton对齐的代码:-

[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];

要设置UIButton的对齐UIButton ,请在Interface Builder中的“属性”检查器中查找按钮。 有一个称为对齐的部分。 将其设置为左侧。 或正确,或任何您想要的。

在此处输入图片说明

为此,请使用UIControlcontentHorizontalAlignment属性。 您可以将其设置为以下任何属性:

UIControlContentHorizontalAlignmentCenter
UIControlContentHorizontalAlignmentLeft
UIControlContentHorizontalAlignmentRight
UIControlContentHorizontalAlignmentFill

[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];

这些选项都没有一个看起来特别好(如您在上面看到的),使用UIButtoncontentEdgeInsets属性来重新定位内容可能会带来更多的运气。

UIButton设置多行标题请查看此论坛帖子 ,其中描述了如何更改按钮标签。

或者,您可以使用此代码快速创建2行按钮:

myButton.titleLabel.textAlignment = UITextAlignmentCenter;
myButton.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
[myButton setTitle:@"Siegfried\nRoy" forState:UIControlStateNormal];

在此处输入图片说明

Raju,别忘了将问题标记为已接受。

实际上,您可以将lineBreakMode设置为UILineBreakModeWordWrapUILineBreakModeCharacterWrap 如有必要,这会将文本分成多行。

尝试这个

    myButton.titleLabel.textAlignment = UITextAlignmentLeft;
    myButton.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
    myButton.titleLabel.numberOfLines = 0;

要添加段落效果,您可以更改标题的大小。

对于阿琳娜效应

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM