我有以下代码...
UILabel *buttonLabel = [[UILabel alloc] initWithFrame:targetButton.bounds];
buttonLabel.text = @"Long text string";
[targetButton addSubview:buttonLabel];
[targetButton bringSubviewToFront:buttonLabel];我的想法是我可以让按钮有多行文本,但文本总是被UIButton的backgroundImage所遮挡。显示按钮的子视图的日志记录调用表明UILabel已被添加,但文本本身不可见。这是UIButton中的一个bug,还是我做错了什么?
发布于 2009-12-02 06:34:56
对于iOS 6和更高版本,请使用以下命令来允许多行:
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
// you probably want to center it
button.titleLabel.textAlignment = NSTextAlignmentCenter; // if you want to
[button setTitle: @"Line1\nLine2" forState: UIControlStateNormal];适用于iOS 5及更低版本的使用以下命令来允许多行:
button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
// you probably want to center it
button.titleLabel.textAlignment = UITextAlignmentCenter;
[button setTitle: @"Line1\nLine2" forState: UIControlStateNormal];2017,对于iOS9 forward,
一般来说,只需要做这两件事:
Break the > Wrap"“
发布于 2014-05-14 23:36:05
选择的答案是正确的,但如果您更喜欢在Interface Builder中执行此类操作,则可以执行以下操作:

发布于 2015-10-21 17:03:54
如果要添加标题以多行居中的按钮,请设置该按钮的界面生成器设置:
[

]
https://stackoverflow.com/questions/604632
复制相似问题