Ser*_*yov 22 cocoa-touch interface-builder uibutton ios
我一直想知道,在Interface Builder中UIButtons有多种方法可以使用多行titleLabel吗?我发现没有,并且UILabel在每个按钮上单独放置并且在按下时跟踪它的颜色并且其他事件不是非常简单.
如果在IB中没有这样的方式,也许在代码中有更好的替代方案?
Mru*_*nal 58
码:
要允许多行,您可以使用:
button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
button.titleLabel.textAlignment = UITextAlignmentCenter;
[button setTitle: @"Line1\nLine2" forState: UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
在iOS 6中,UILineBreakModeWordWrap并且UITextAlignmentCenter被弃用,因此,使用方法:
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
button.titleLabel.textAlignment = NSTextAlignmentCenter;
Run Code Online (Sandbox Code Playgroud)
界面生成器: