Change the label width dynamically inside a UITableViewCell

后端 未结 3 1224
忘掉有多难
忘掉有多难 2021-01-03 12:15

I am trying to build up an custom table view.

\"enter

As you can see in the pi

相关标签:
3条回答
  • 2021-01-03 12:37

    If you are using auto layout, you can just set the x and y position, and then nothing for the height and width, and the label will correctly size itself to fit its contents. One caveat if you are using Xibs or Storyboards, don't put any text in your label in the storyboard, or it will want to size to that text. So delete the placeholder text from the storyboard, set the constraints and then you will be good to go.

    0 讨论(0)
  • 2021-01-03 12:48

    You can also create and position the UILabel programatically, this way the iOS auto-layout will not interfere with your frame change.

    0 讨论(0)
  • 2021-01-03 12:51

    This sounds like a consequence of auto layout -- when using it, you shouldn't set frames at all, instead you should adjust the constraints. You can make an IBOutlet to the width constraint of your label, and adjust its constant value in code.

    0 讨论(0)
提交回复
热议问题