Sunday, 15 September 2013

uitableview - iOS UILabel width doesn't fit inside table cell -


I'm new to iOS development. I have a problem when inserting the label into theUtiviewelCell. The text keeps going out of the cell; I connect all the necessary obstacles but it does not work. Here's my setup and code:

  Title label attributes: Number of rows -0, line breaks -Word wrap  

viewDidLoad ():

  Automated view. Estimated rocket = 68.0; Self.tableView.rowHeight = UITableViewAutomaticDimension;  

cellForRowAtIndexPath ():

  UILabel * titleLabel = (UILabel *) [cell view details: 100]; TitleLabel.text = @ "Why does this long text get out of the cell? Accelerated brown shorts jump on the lazy dog, quick brown shirts jump on lazy dogs, quick brown jumps on lazy dogs jumps. The fox jumps over the lazy dogs. The quick brown fox jumps over the celestial dog. ";  

I am using xcode 6.2 and ios 8.2.

Thanks for any help.

Screenshots:
Enter image details here

Cell prototype: Enter image details here

Title label constraints:
Enter image details here

To keep your text, you need to do two things in the label's borders and in the cell.

  1. If the label width is fixed, then the height of your cell depends on the height of the label (which is derived from its contents). As you have already provided Estimated Rohit and rowHeight as UITableViewAutomaticDimension . So this is fine.
  2. The label must be limited to width / unless it reaches the extreme right of the cell. Also, please also ensure that if the width of the label is flexible then it should also be added to the right side. Alternatively, you can write the code below the API based on the calculation of the height of the label. The contents of the label will determine the height of the cell. And finally create the cell label

    While assigning the text to iOS 7 and above.

      #define LABELS_MAX_HEIGHT10000.0f CGSize constraintSize = CGSizeMake (label.frame. Size.width, LABELS_MAX_HEIGHT); NSAttributedString * attributedText = [[[NSAttributedString alloc] initWithString: Text attributes: @ {NSFontAttributeName: label.font}] Autorelage]; CGRAct Rect = [Attributed Test BoundingRightWith Size: Hurdle Selection Option: NSSSDeading DrawingSignlineFragmentOgreen Theme: Nyl]; StrSize = rect.size;  

No comments:

Post a Comment