UILabel resizing in UITableViewCell

Discussion in 'iOS Programming' started by arnieterm, Feb 25, 2010.

  1. arnieterm macrumors regular

    Aug 28, 2008
    Hi All,
    I have a custom UITableViewCell with two UILabels [field-value] pairs. The value label needs to be multiline. Using the heightForRowAtIndexPath and cellForRowAtIndexpath of UITableView, I am able to resize both the cell and the respective UILabel to show complete text.
    The problem is that in case of multiline label the text appears slightly dipped which results in both the labels [field and value pair] as not appearing in same horizontal line. I am making use of sizeWIthFont with constraint of NSString to determine the resultant height of the text and the function returns correct height.
    But resizing the value label dips the text slightly [may be due to the adjustment of its center].
    How can I prevent this?
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    By dipped I assume that you mean that the text in the two labels that are side by side doesn't line up exactly vertically.

    Labels center their text vertically. So you need to adjust the height of the one-line label so its text aligns with the baseline of the multiline label. Basically if you make the height of the labels a little shorter the text will move up. This also depends on the size of the font you're using.

Share This Page