简体   繁体   中英

iOS: Resizing TableView depending on screen size

I'm trying to have a tableview resize depending on the screen size. The app is designed for iPhone 6, so it should basically shrink if the screen is smaller. I tried using constraints and pinning to superview, but it only seems to work for the height. I'm thinking I might have to resize the cells as well, but I'm not sure how to do it.

I know the question is very general, but I absolutely don't know the first thing about this.

Thanks for your help.

You need to use autolayout for both your tableview and your cells, otherwise ios will just try to guess the missing constraints (poorly). Make sure you set both horizontal and vertical constraints.

If you can disable autolayout and use AutoResizing , it might be easy. After disabling the autolayout select your table in xib and go to Size inspector on Right Pane. In that set the auto resizing as follows

图片

It can adjust the height and width automatically. No matter the size of screen is.

Additional: If you have excess of empty rows at the bottom hiding the size, you can remove it by the following code:

self.table.tableFooterView = UIView()

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