调整标签大小以适应文本数量 - Swift [英] Resize label to fit text amount - Swift

查看:30
本文介绍了调整标签大小以适应文本数量 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿 :) 我有一个标签,我需要根据文本量缩小或扩大该标签的宽度,我只找到了如何调整文本以适应大小的方法,但找到了如何将大小调整为适合文字,有什么想法吗?

Hey :) I have a label and I need to make the width of that label smaller or larger accourding to the text amount, and I found only how to adjust the text to fit the size but the how to adjust the size to fit the text, any ideas ?

推荐答案

您需要这样做:

myLabel.sizeToFit()

如下所示:https://developer.apple.com/documentation/uikit/uiview/1622630-sizetofit

这将更新标签的框架以适应内容.然后,您可以根据需要放置它或在此之后进行任何编辑.

This will update the label's frame to fit the content. You can then place it or make any edits after this that you want.

这篇关于调整标签大小以适应文本数量 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆