How to adjust a label size to fit the length of the text

前端 未结 8 692
无人及你
无人及你 2020-12-20 12:27

I have searched the solution to this in the past QAs, but could not find the right one.
Does anyone know how to adjust aUILabel size dynamically to fit the

相关标签:
8条回答
  • 2020-12-20 12:55

    What you are searching is the UILabel method sizeToFit

    I can try to explain to you, but the best answer to know how to work with UILabel is that: https://stackoverflow.com/a/1054681/666479

    0 讨论(0)
  • 2020-12-20 12:55

    you get simply calculate UILabel width for string size,try this simple code for set UILabel size

       // Single line, no wrapping;
        CGSize expectedLabelSize = [string sizeWithFont:yourFont];
     //  you get width,height in expectedLabelSize;
    //expectedLabelSize.width,expectedLabelSize.height
    
    0 讨论(0)
提交回复
热议问题