gpt4 book ai didi

ios - InterfaceBuilder 中带有多行 titleLabel 的 UIButton

转载 作者:IT王子 更新时间:2023-10-29 08:00:14 26 4
gpt4 key购买 nike

我一直在想,有没有什么好的方法可以在 Interface Builder 中制作带有多行 titleLabelUIButtons?我没有发现任何东西,并在每个按钮顶部放置一个单独的 UILabel 并在按下时跟踪它的颜色和其他事件并不是很简单。

如果 IB 中没有这样的方法,也许有更好的代码替代方法?

最佳答案

代码:

要允许多行,您可以使用:

button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
button.titleLabel.textAlignment = UITextAlignmentCenter;
[button setTitle: @"Line1\nLine2" forState: UIControlStateNormal];

iOS 6 中,UILineBreakModeWordWrapUITextAlignmentCenter 已弃用,因此请使用:

button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
button.titleLabel.textAlignment = NSTextAlignmentCenter;

界面生成器:

  • 在界面生成器中选择UIButton
  • Attributes Inspector 下右侧的 Utilities Pane 中,您会看到Line Break 的选项
  • 选择自动换行

关于ios - InterfaceBuilder 中带有多行 titleLabel 的 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18659832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com