before updating to iOS 26 my list was looking fine but now it has abnormal paddings and because I am using fixed height, I had to increase the height from 40 to 60 to fit the text. There are currently two issues I am facing.

The list is now not being clipped at the bottom edges when I increase the height to 60 When the text is more than one line, unlike before it does not decrease padding to fit it in the specified height but instead cuts it off.

Following are my modifiers for my view, I have also treid with minHeight and mxHeight but both issues persist

struct SwiftUIView: View { var body: some View { let names = [Name(name: "Name 1"), Name(name: "Name 2 Name Double line list row text which should fit in it too")] ZStack { Color(.pink) List { Section { ForEach(names) { name in Button { // do action } label: { Text(name.name) } } } } .listStyle(.plain) .clipShape(.rect(cornerRadius: 15)) .scrollContentBackground(.hidden) .layoutPriority(1) .frame(height: 2 * 52) .padding(10) } } }

Desired behaviour is that like before iOS 26 the padding would decrease for a row when the text is multiline.

iosDev73's user avatar

6

As discussed in the comments, the modifier .onScrollGeometryChange can be used to measure the height of the list precisely (requires iOS 18). You can then set this height on the list, before applying the clip shape. This approach also adapts to changes in the text size.

Here is the fully updated example to show it working:

struct SwiftUIView: View { let names = [ Name(name: "Name 1"), Name(name: "Name 2 Name Double line list row text which should fit in it too") ] @State private var listHeight: CGFloat? var body: some View { ZStack { Color.pink .ignoresSafeArea() List { Section { ForEach(names) { name in Button { // do action } label: { Text(name.name) } } } } .listStyle(.plain) .onScrollGeometryChange(for: CGFloat.self, of: \.contentSize.height) { _, height in if height > 0 { listHeight = height } } .frame(height: listHeight) .clipShape(.rect(cornerRadius: 15)) .scrollContentBackground(.hidden) .padding(10) } } } struct Name: Identifiable { let id = UUID() let name: String }

Screenshot

Benzy Neez's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.