gpt4 book ai didi

ios - 如何快速将文本包装在 UIButton 上

转载 作者:搜寻专家 更新时间:2023-10-31 21:53:40 24 4
gpt4 key购买 nike

我尝试按如下方式在按钮上包装文本:

nextButton=UIButton(frame: CGRectMake(buttonHWidth, textHeigth, buttonHWidth, buttonHeigth));

nextButton.backgroundColor = UIColor.lightGrayColor()
nextButton.setTitle("", forState: UIControlState.Normal)
nextButton.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
nextButton.tag = 22;


label_nextButton = UILabel(frame: CGRectMake(buttonHWidth, textHeigth, buttonHWidth, buttonHeigth));
label_nextButton.textAlignment = NSTextAlignment.Center;
label_nextButton.numberOfLines = 2;
label_nextButton.font = UIFont.systemFontOfSize(16.0);
label_nextButton.text = "Prss next Press next";
label_nextButton.textColor=UIColor.blackColor();

nextButton.addSubview(label_nextButton);
self.view.addSubview(nextButton);

我可以看到设备上的按钮,但看不到任何文本。

我做错了什么?或者这可以在不向按钮添加标签的情况下完成吗?感谢您的帮助。

插图。看起来像:

enter image description here

刚刚做的时候:

nextButton.setTitle("this is a very very long text", forState: UIControlState.Normal)

最佳答案

需要在setTitle方法中写入文字:

nextButton.setTitle("This is the very very long text!", forState: UIControlState.Normal)

设置标题标签的行数和换行方式:

nextButton.titleLabel.numberOfLines = 0; // Dynamic number of lines
nextButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;

Update to Swift 4

nextButton.titleLabel.numberOfLines = 0; // Dynamic number of lines
nextButton.titleLabel.lineBreakMode = NSLineBreakMode.byWordWrapping;

关于ios - 如何快速将文本包装在 UIButton 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29847361/

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