简体   繁体   中英

UITableView to always show 4 cells

I want my UITableView to always show 4 rows, whether it's on retina 3.5 or 4 - with appropriate re-sizing of fonts and subviews in the cell. The app will always be in portrait orientation.

Is there an "elegant" way to do this in storyboard or through constraints?

Or is the best way to determine all the sizes manually, then alter them programmatically?

Set Auto-resize property of UITableView with flexible height, so that it could change height on devices having different screen sizes. Use heightForRowAtIndexPath like this:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.yourTableView.frame.size.height/4;
}

Now, whatever the height of tableview is, you will get same cell heights for all 4 cells.

Note: For your UITableViewCells set view and elements resize properties like flexible height and flexible positions, so that cells' elements get adjusted according to height changes.

我不明白您的问题,但是如果您要指定单元格高度,则可以使用UITableViewDelegate方法:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM