bcylin / QuickTableViewController

A simple way to create a UITableView for settings in Swift.

Home Page:https://bcylin.github.io/QuickTableViewController

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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!

Simulator Screen Shot - iPad (8th generation) - 2021-06-18 at 02 24 19

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

Simulator Screen Shot - iPad (8th generation) - 2021-06-18 at 02 24 28

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.

commented

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.

/// Returns the table view managed by the controller object.
open var tableView: UITableView = UITableView(frame: .zero, style: .grouped)

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.