UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Help with alignment of text in UITableView inset grouped header using UIListContentConfiguration

Forums > Swift

Hi everyone,

I am currently learning how to use content configuration (UIListContentConfiguration, etc., introduced WWDC '20) in UITableView, instead of the now deprecated tools such as cell.textLabel?.text.

I am trying to implement a section header on an inset grouped table view using the UIListContentConfiguration.groupedHeader() configuration with a UITableViewHeaderFooterView. However, when I do so, the text is misaligned, several pixels to the left of the cell content's text, aligned with what I assume is text for the grouped table view style rather than the inset grouped table view style.

Here is an ascii art version, as I couldn't figure out how to add images using markdown :)

  HELLO                    <--- Header
____________________
|
|     Favorites                   <--- Table View Cell text
|     

The cell is using the UIListContentConfiguration.valueCell() configuration, in an inset grouped table view. Here is the code for my header:

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView: UITableViewHeaderFooterView = UITableViewHeaderFooterView()

        var content = UIListContentConfiguration.groupedHeader()

        content.text = "Hello"

        headerView.contentConfiguration = content

        return headerView
}

Is there a place to add a layout guide, or constraints I don't know about? Is there another inset grouped style I just don't know about?

Any guidance would be greatly appreciated!

Thank you!

-Thomas

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.