UIButton label text is being clipped(UIButton 标签文本被剪裁)
问题描述
我在 Interface Builder 中内置了一个具有默认标签的 UIButton.在 Xcode 中,我正在动态更改标签文本,如下所示:
I have a UIButton built in Interface Builder that has a default label. In Xcode, I'm changing the label text dynamically like so:
myButton.titleLabel.text = @"this is the new label";
但是,当文本更新时,新字符串被剪裁到与原始字符串相同的大小,最终看起来像:
However, when the text updates, the new string is being clipped down to the same size as the original string and ends up looking like:
this...label
有人知道为什么会这样吗?
Anyone know why this is happening?
推荐答案
你应该使用 setTitle:forState: 更改 UIButton
的标题.如果您自己更改标题,则按钮不会显示需要调整标签大小 - 您最终将不得不执行以下操作:
You should use setTitle:forState: to change the title of a UIButton
. If you change the title yourself, the button has no indication that it needs to resize the label – you'd end up having to do something like this:
myButton.titleLabel.text = @"this is the new label";
[myButton setNeedsLayout];
但我什至不确定这是否适用于所有情况.提供了诸如 setTitle:forState:
之类的方法,以便您可以为多个状态提供标题,而无需手动更新按钮,并且按钮知道需要使用新标题对其进行布局.
but I'm not even sure that would work in all cases. Methods like setTitle:forState:
are provided so that you can provide titles for multiple states without having to update the button manually, and so that the button knows that it needs to be laid out with a new title.
这篇关于UIButton 标签文本被剪裁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIButton 标签文本被剪裁
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01