Quote:
Originally Posted by vijayeta
CGSize textSize = { width, 20000.0f };// width and height of text area
can any one please tell me why 20000.0f is used as the height ?? when i try to use the above code snippet , the cell height isnt proper , for text with 1 line it wroks fine , but 2 - 3 lines the cell size is too big.
|
vijayeta,
The idea is to create a CGSize that's as wide as your text field, but very tall. Then you call the NSString method -sizeWithFont and ask the string how tall it would be at the specified font and field width. To calculate cell height you then need to add the origin.y of the text field, plus any space you need below the text field, to get the final cell height.
Here's a snippet of the code I use in my heightForRowAtIndexPath method:
Code:
CGSize tempSize;
CGSize theTextSize;
tempSize.width = theTableWidth-(10+ 7 + kImageSize);
tempSize.height = 9999;
theTextSize = [theText sizeWithFont: theFont constrainedToSize: tempSize];