To use them, first create an object that will store its value, then check the value of that property whenever you need, looking for either the. SwiftUI supports size classes natively by exposing them in the environment for us to read. It would appear that not everybody is working on SwiftUI yet.How to create different layouts using size classes Scroll View Layout With Interface Builder.It’s not the only example of some dusty corners of Interface Builder getting some polish. I’ve no idea why the Xcode engineers suddenly decided to fix this in Xcode 11. Note that anytime you manually change the row height of the cell in the canvas it disables the “Automatic” setting in the size inspector. If you change the text style of the text view the cell resizes in the canvas to take into account the new content size: The table view cell in the canvas is finally self-sizing: If you select it Interface Builder wakes up and realizes you have created a self-sizing cell (you can just about read the actual row height of 346.5 points): (35735970)Īssuming you have switched to Xcode 11, this is how the size inspector looks for the table view cell: To opt into the behavior for existing table views, enable “Automatic” for the table view estimated item size, and “Automatic” for cell’s height in the Size inspector. Here’s the good news buried in the Xcode 11 release notes:Ĭells in a UITableView can now self size with Auto Layout constrained views in the canvas. If you unclick the “Custom” checkbox the row height goes back to the default:Įither way, Xcode 10 never shows the table view cell at the correct size for the placeholder content: Note that changing this row height only changes the height of the cell in Interface Builder - it doesn’t change the row height at runtime. You can see the fixed size the cell takes in the canvas if you select the cell (not the table view) and look in the size inspector. It continues to show the cell as being 100 points high truncating most of the text view. I added four constraints to pin it to the margins of the content view:Īt this point we have a valid layout that is self-sizing when I run it but Interface Builder is none the wiser. The text view has scrolling disabled and is using the. I’ve added a text view with a several lines of placeholder text. I usually find it best to drag the bottom of the cell down to make some space. The prototype cell in Interface Builder doesn’t give you a lot of room to work with. The table view row height and estimated row height both default to “Automatic”: Set a non-zero value for the estimated row height (or use “Automatic”).ĭoing this in Interface Builder should be straightforward.Set the table view height to “Automatic”.Add constraints to fully constrain, vertically and horizontally, your subviews to the content view (not the cell itself).Add your subviews to the content view of the table view cell.To create one follow these rules when laying out the cell: To recap, a “self-sizing” table view cell should adjust its height to fit the content of the cell at its natural height. That’s finally fixed in Xcode 11! What’s The Problem? Interface Builder added to the confusion by not automatically sizing the cells in the canvas. Self-sizing table view cells have been around a long time but are still a regular source of confusion.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |