Set the variable height of UITableViewcell according to the width of UITableViewcell – iPhone

In the IPhone tableview, the content width is 320 or 300, depending on the style. However, when the Ipad is on the stage, we start to use tableviews of different widths according to our design. < p>

One problem is that in some cases, we calculate the height of the cell based on its subtitle text size. The text height depends on the contentwidth, and the cell height depends on the text height. If the width is 300 Or 320, it’s ok. But I think I used a grouped style view that is 500 pixels wide and cannot calculate the reduced content width. Due to this problem, we cannot calculate the height of the call based on its content.

The only place where we can get information about the cell content width is in the subclass layout subview method. However, heightForRowAtIndexPath is called before the layoutSubview method, and we have no information about shrinking the cell content width.

So , We need a good way to calculate the true width of the grouped style tableview cell.

I will be glad to get any help.

Thank you.

M Ali Caliskan

Finally I solved the problem of the width of the grouped tableView. The standard 320 width of 10( On one side) the padding size varies according to the width through interesting math. The easy way to deal with this math is to use a fixed value based on the width range. The code below works for 4.0, I haven’t tested it on any other iOs version.

Please multiply the returned padding size by 2 to find the total reduction of the grouping style tableView. For example, if the paddign size is 10 for a 320-pixel-wide tableView, the contentWidth is 320-(2.10 )= 300.

CGFloat GetTableViewPaddingSize(CGFloat tableViewWidth)
{
if (tableViewWidth <401) {
return 10;
} else if (tableViewWidth <547) {
return 31;
} else if (tableViewWidth <560) {
return 32;
} else if (tableViewWidth <573) {
return 33;
} else if (tableViewWidth <586) {< br /> return 34;
} else if (tableViewWidth <599) {
return 35;
} else if (tableViewWidth <612) {
return 36;
} else if (tableViewWidth <625) {
return 37;
} else if (tableViewWidth <639) {
return 38;
} else if (tableViewWidth <652) {< br /> return 39;
} else if (tableViewWidth <665) {
return 40;
} else if (tableViewWidth <678) {
return 41;
} else if (tableViewWidth <691) {
return 42;
} else if (tableViewWidth <704) {
return 43;
} else if (tableViewWidth <717) {< br /> return 44;
} else {
return 45;
}
}

In the IPhone tableview, The content width is 320 or 300, depending on the style. However, when When the iPad is on the stage, we start to use tableviews of different widths according to our design.

One problem is that in some cases, we calculate the height of the cell based on its subtitle text size. The text height depends on the contentwidth, and the cell height depends on the text height. If the width is 300 or 320, it is ok. But I think I used a grouped style view of 500 pixels wide and I cannot calculate the reduced content width. Because of this The problem, we cannot calculate the height of the call based on its content.

The only place where we can get information about the width of the cell content is the subclass layout subview method. However, the heightForRowAtIndexPath is called before the layoutSubview method, and we There is no information about shrinking the content width of the cell.

Therefore, we need a good way to calculate the true width of the grouped style tableview cell.

I will be very happy Get any help.

Thank you.

M Ali Caliskan

Finally I solved the problem of the width of the grouped tableView The padding size of 10 (on one side) of the standard 320 width varies according to the width through interesting math. The easy way to deal with this math is to use a fixed value based on the width range. The code below is valid for 4.0, I did not use any other iOs Test it on the version.

Please multiply the returned padding size by 2 to find the total reduction of the grouping style tableView. For example, if the paddign size is 10 for a tableView that is 320 pixels wide, Then the contentWidth is 320 – (2.10) = 300.

CGFloat GetTableViewPaddingSize(CGFloat tableViewWidth)
{
if (tableViewWidth <401) {
return 10;
} else if (tableViewWidth <547) {
return 31;
} else if (tableViewWidth <560) {
return 32;
} else if (tableViewWidth <573) {
return 33;
} else if (tableViewWidth <586) {
return 34;
} else if (tableViewWidth <599) {
return 35;
} else if (tableViewWidth <612) {
return 36;
} else if (tableViewWidth <625) {
return 37;
} else if (tableViewWidth <639) {
return 38;
} else if (tableViewWidth <652) {
return 39;
} else if (tableViewWidth <665) {
return 40;
} else if (tableViewWidth <678) {
return 41;
} else if (tableViewWidth <691) {
return 42;
} else if (tableViewWidth <704) {
return 43;
} else if (tableViewWidth <717) {
return 44;
} else {
return 45;
}
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1121 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.