I am using a custum UITableViewCell that can display some labels, buttons and image views. The cell has a label whose text is a NSString
object and the length of the string can be variable due to this, I can not set a static height on the cell in UITableViews: heightForCellAtIndex
The height of the method cell depends on the height of the label which can be determined by using the NSStrings
sizeWithFont
method. I tried to use it, but it seems I'm going wrong somewhere. How can this be fixed?
Here the code is used to start the cell.
if (auto = [super initWithFrame: frame re-user: reuseIdentifier]) {self selection style = UITableViewCellSelectionStyleNone; UIImage * image = [UIImage imageNamed: @ "dot.png"]; ImageView = [[UIImageView alloc] initWithImage: Image]; ImageView.frame = CGRectMake (45.0,10.0,10,10); HeadingTxt = [[UILabel alloc] initWithFrame: CGRectMake (60.0.0.0,150.0, post_HDG_HT)]; [HeadingTit Set ContentMode: UIViewContentModeCenter]; HeadingTxt.text = postData.user_f_name; HeadingTxt.font = [UIFont boldSystemFontOfSize: 13]; HeadingTxt.textAlignment = UITextAlignmentLeft; HeadingTxt.textcolor = [UIColor blackcolor]; DateTxt = [[UILabel alloc] initWithFrame: CGRectMake (55.0, 23.0,150.0, post_dataite)]; DateTxt.text = postData.created_dtm; DateTxt.font = [UIFont ITALIC FONTOFF size: 11]; DateTxt.textAlignment = UITextAlignmentLeft; DateTxt.textColor = [UIColor gray color]; NSString * text1 = postData.post_body; NSLog (@ "text length =% d", [text1 length]); CGRect border = [UIScreen home screen]. Bounce; CGFloat tableViewWidth; CGFloat width = 0; TableViewWidth = bounds.size.width / 2; Width = tableViewWidth - 40; // Manipulation Factor // CGSize Text Size = {Width, 20000.0 F}; // Text field width and height CGSize textSize = {245.0, 20000.0f}; // Text area width and height CGSize size1 = [text1 size fonts: [UIFont systemFontOfSize: 11.0f] constrained size: Text Size LineComed: UILineBreakModeWordWrap]; CGFloat ht = MAX (size 1.high, 28); TextView = [[UILabel alloc] initWithFrame: CGRactam (55.042.0245.0, HT)]; TextView.text = PostData. Post_body; TextView.font = [UIFont systemFontOfSize: 11]; TextView.textAlignment = UITextAlignmentLeft; TextView.textColor = [UIColor black color]; TextView.lineBreakMode = UILineBreakModeWordWrap; TextView.numberOfLines = 3; TextView.autoresizesSubviews = Yes; [Self.contentView addSubview: imageView]; [Self.contentView addSubview: textView]; [Self.contentView addSubview: webView]; [Self.contentView addSubview: dateTxt]; [Self.contentView addSubview: headingTxt]; [Self. See content size tofitt]; [See image release]; [See text release]; [Webview release]; [DateTxt release]; [HeadingText release]; }
visible = [[UILabel alloc] initWithFrame: CGRectMake (55.0.442.0,245.0, HT)]
This label whose height and width are going wrong.
Your UITableViewDelegate
should be implemented tableView: heightForRowAtIndexPath: < / Code>
- (CGFloat) Table view: (UITableView *) Table view height ForRowAtIndexPath: (NSIndexPath *) indexPath {return [indexPath row] * 20; }
You probably want to experiment with the NSString
size: constrained burst: bandwidth: lineback command: your line height Instead of computing, display some silly math on method IndexPath :)
Comments
Post a Comment