1

i'm currently making an app where the suer selects an MKMapView annotation and then the title of the annotation(pin) is set to a detailtextLabel in a Right Detail UITableViewCell. My Problem is that when the text is large, the detailTextLabel becomes multiple lines. When this happens the TextLabel of the cell(the one the left) shifts up. Heres What I've tried:

  • In the cellForRowAtIndexPath Method, I tried adjusting the frame through the following code:
    CGRect frame = cell.textLabel.frame;

    frame.origin.y = cell.frame.size.height/2;

    cell.textLabel.frame = frame;

    Where cell is a UITableViewCell that is set to right detail

  • Subclass the cell and tun try to adjust the frame in the -(void)layoutSubviews

How do I stop it from going up and keep it at the center of the cell?

virindh
  • 3,775
  • 3
  • 24
  • 49

2 Answers2

1

If you want to do a custom layout of UITableViewCell, then you need to add your custom UI elements to its -[UITableViewCell contentView] instead of trying to modify geometry of standard UI elements that are created by default.

So, in your case, you need to add two UILabels and set their position so that:

  1. Title label will not move at all
  2. Detail text label will be also multiline

In this way you'll be able to solve this problem!

art-divin
  • 1,635
  • 1
  • 20
  • 28
0

Please try to make the font size adjustable amount to the text. I think you can use,

cell.detailTextLabel.adjustFontSizeToWidth = Yes; And also set the numberOfLines to 0.

Hope that solves the purpose.

Balram Tiwari
  • 5,657
  • 2
  • 23
  • 41