Resize label to fit text amount - Swift

南楼画角 提交于 2019-12-06 17:11:15

问题


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 ?


回答1:


You'll want to do this:

myLabel.sizeToFit()

As seen here: 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.



来源:https://stackoverflow.com/questions/31592272/resize-label-to-fit-text-amount-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!