How to get the modernUI with rounded corners? π§
keshaaaav opened this issue Β· comments
First of all, thank you so much for this!
I was testing the Demo build and it has this modern UI with rounded corners β It looks pretty nice!
but, after adding the dependency, I set the whole thing up (by adding tableContents
in viewDidLoad
) but I have this old UI with sharp corners
I scratched my head for sometime and realized I might want to add this:
init() {
if #available(iOS 13.0, *) {
super.init(style: .insetGrouped)
} else {
super.init(style: .grouped)
}
let titleLabel = UILabel()
titleLabel.text = "QuickTableViewController"
titleLabel.font = UIFont.boldSystemFont(ofSize: 17)
title = " "
navigationItem.titleView = titleLabel
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented") }
because this was the only thing that was not in my code but it was present in demo build, but my app crashes with a Fatal Error init(coder:) has not been implemented
Thank you.
Thanks for using QuickTableViewController.
The UI with rounded corners is UITableView.Style.insetGrouped, which requires iOS 13+. The default table view style is .grouped
because QuickTableViewController still supports iOS 8. You can use QuickTableViewController.init(style:)
to initilise the view controller in code with a different style.
QuickTableViewController/Source/QuickTableViewController.swift
Lines 35 to 36 in 29fbe93
But I guess you are using a storyboard so the view controller is initialised via init?(coder:)
. The demo app in the project does not have the implementation for storyboards. That's why there's the fatal error from the demo code you copied.
One solution for storyboards is to override the table view after the initialisation from init?(coder:)
. The frame does not matter here because the layout is set up during viewDidLoad()
.
required init?(coder: NSCoder) {
super.init(coder: coder)
if #available(iOS 13.0, *) {
tableView = UITableView(frame: .zero, style: .insetGrouped)
}
}
Hope this helps.