调整 UILabels 的大小以适应内容?
问题说明
我的程序目前有 30 个 UILabel,其中可能包含一到三位数的数字.我希望我的 UILabels 随着其中的数字改变大小而水平扩展和收缩.目前文本正在缩小,UILabels 大小保持不变.
My program currently has thirty UILabels that may contain numbers between one and three digits. I want my UILabels to expand and shrink horizontally as the numbers within them change size. At the moment the text is shrinking and the UILabels size remains the same.
如果这可以仅使用 xib 文件来完成,这将比以编程方式执行此操作更可取,但如果这不可能,则两者都很棒.
If this can be done just using the xib file this would be preferable to doing so programmatically but if this isn't possible either would be great.
谢谢
正确答案
设置标签文本后,在标签上调用sizeToFit
.这将使标签刚好足以容纳文本.
After setting the text of the label, call sizeToFit
on the label. This will make the label just big enough for the text.
顺便说一句 - 你为什么需要这样做?为什么不让标签足够大以容纳可能的值并让它们保持那个大小?您认为缩小标签会带来什么好处?
BTW - why do you need to do this? Why not just make the labels big enough for the possible values and leave them that size? What benefit do you think you will get by shrinking the labels?
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgkjgi
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
复制文件夹/文件而不修改属性?
it1352 07-15