问题
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