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

前端 未结 8 732
无人及你
无人及你 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条回答
  •  萌比男神i
    2020-12-20 12:51

    You can use this piece of code for calculate label width and set it

       CGSize expectedLabelSize = [name sizeWithFont:yourfont constrainedToSize:maximumLabelSize]; 
    

    // you can get width width height from expectedLabelSize and set accordingly

提交回复
热议问题