Josue Espinosa
Josue Espinosa

Reputation: 5089

UITableViewCell layout problems

I have a simple custom UITableViewCell that looks like this:

enter image description here

The problem is, I'm trying to make the title label as wide as possible, while remaining x pixels from the image and the 9.9 label. I try to do this by setting constraints on the image (left padding) and 9.9 label (right padding), but then Xcode complains that the horizontal settings for the 9.9 label are ambiguous.

Can anyone help me give the title label a dynamic width without destroying the 9.9 label's constraint to the right?

Upvotes: 0

Views: 120

Answers (2)

Rory McKinnel
Rory McKinnel

Reputation: 8014

Probably a bit late, but you have 2 labels which can grow or shrink. Since you have given the constraints no clues, the code can not decide if Title should grow or 9.9 should grow to fit the width of the screen.

You can adjust the horizontal hugging/compression of the Title so that it grows before the 9.9 label would. This means you can avoid using fixed widths.

Upvotes: 3

KDaker
KDaker

Reputation: 5909

I think it will work if you constraint the 9.9 label with a fixed width (assuming you know its size won't change).

so from the left:

  • Image has left constraint of 0
  • Image has proportion constraint
  • Title label has constraint to image of x pixels
  • Title has right constraint to 9.9 of x pixels
  • 9.9 has fixed width constraint
  • 9.9 right constraint of x pixels

Hope this helps

Upvotes: 1

Related Questions