A subclass of UITableView that styles it like Settings.app on iPad

Overview

TORoundedTableView

TORoundedTableView

CI Version Carthage compatible GitHub license Platform Beerpay PayPal Twitch

As of iOS 13, Apple has released an official version of this table view style called UITableViewStyleInsetGrouped! Yay! In order to officially adopt this style, while still providing backwards compatibility to iOS 11, I've created a new library called TOInsetGroupedTableView. Moving forward, please only use TORoundedTableView if you still need to support iOS 10 or lower in your apps. :)

TORoundedTableView is a subclass of the standard UIKit UITableView class. Harkening back to the days of iOS 6, it overrides the standard grouped UITableView appearence and behaviour to match the borderless, rounded corner style seen in the Settings app on every iPad since iOS 7.

As iOS device screens increased (Like iPhone 6 Plus and the original iPad Pro), there are a lot of UI design cases where the 'edge-to-edge' style of the stock grouped UITableView doesn't make sense, and will end up looking rather distorted in ultra-wide regions.

Features

  • Integrates with UITableViewController (On account of the tableView property being mutable!)
  • Relatively autonomous operation with only a few extra APIs required.
  • Optimized to the absolute nth-degree to ensure no drops in performance or broken animations.
  • Reverts back to the standard table view style in compact trait collections (Just like in Settings.app)
  • Corner radius graphics are procedurally generated and can be customized on the fly.

Sample Code

TORoundedTableView can easily be integrated into UITableViewController all you need to do is replace the UITableView object stored in the controller's tableView property befor it is shown on-screen.

TORoundedTableView tries to be as hands-off as possible in the amount of extra delegate / dataSource code necessary to write. However, in order to ensure maximum efficiency, a few extra bits of code are required:

In a standard UITableViewController implementing TORoundedTableView, the tableView:cellForRowAtIndexPath: data source method would look like this:

- (UITableViewCell *)tableView:(TORoundedTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    /*
     Because the first and last cells in a section (dubbed the 'cap' cells) do a lot of extra work on account of the rounded corners,
     for ultimate efficiency, it is recommended to create those ones separately from the ones in the middle of the section.
    */
    
    // Create identifiers for standard cells and the cells that will show the rounded corners
    static NSString *cellIdentifier     = @"Cell";
    static NSString *capCellIdentifier  = @"CapCell";
    
    // Work out if this cell needs the top or bottom corners rounded (Or if the section only has 1 row, both!)
    BOOL isTop = (indexPath.row == 0);
    BOOL isBottom = indexPath.row == ([tableView numberOfRowsInSection:indexPath.section] - 1);
    
    // Create a common table cell instance we can configure
    UITableViewCell *cell = nil;
    
    // If it's a non-cap cell, dequeue one with the regular identifier
    if (!isTop && !isBottom) {
        TORoundedTableViewCell *normalCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (normalCell == nil) {
            normalCell = [[TORoundedTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        }
        
        cell = normalCell;
    }
    else {
        // If the cell is indeed one that needs rounded corners, dequeue from the pool of cap cells
        TORoundedTableViewCapCell *capCell = [tableView dequeueReusableCellWithIdentifier:capCellIdentifier];
        if (capCell == nil) {
            capCell = [[TORoundedTableViewCapCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:capCellIdentifier];
        }
        
        // Configure the cell to set the appropriate corners as rounded
        capCell.topCornersRounded = isTop;
        capCell.bottomCornersRounded = isBottom;
        cell = capCell;
    }

    // Configure the cell's label
    cell.textLabel.text = [NSString stringWithFormat:@"Cell %ld", indexPath.row+1];
    
    // Since we know the background is white, set the label's background to also be white for performance optimizations
    cell.textLabel.backgroundColor = [UIColor whiteColor];
    cell.textLabel.opaque = YES;
    
    // Return the cell
    return cell;
}

Installation

TORoundedTableView will work with iOS 8 and above. While written in Objective-C, it should easily import into Swift as well.

Manual Installation

To manually install this library in your app, simply download a copy of this repo. When the download has completed, copy the contents of the TORoundedTableView folder to your app project folder, and then import it into your Xcode project.

CocoaPods

To integrate TORoundedTableView, simply add the following to your podfile:

pod 'TORoundedTableView'

Carthage

To integrate TORoundedTableView, simply add the following to your Cartfile:

github "TimOliver/TORoundedTableView"

Classes

TORoundedTableView consists of 4 separate classes that are used in tandem together to achieve the desired functionality.

TORoundedTableView

A very basic subclass wrapper for UITableView that overrides the original 'edge-to-edge' philosophy by manually re-laying out all of the content views in a more narrow column. It also creates and manages the rounded corner image assets, so they can be efficiently shared amongst all cells.

TORoundedTableViewCell

A very small wrapper for UITableViewCell that internally overrides the cell's frame property, constraining all cells to the narrower column width of the parent TORoundedTableView.

TORoundedTableViewCapCell

A subclass of TORoundedTableViewCell that provides the additional logic needed to manage the views responsible for drawing the rounded corners, and overriding the UITableViewCell behaviour of placing hairline borders on the top and bottoms of sections.

TORoundedTableViewCellBackground

The view in charge of drawing the rounded edges on the cells at the top and bottom of the section, instances are set as the backgroundView and selectedBackgroundView for each TORoundedTableViewCapCell. The drawing is handled by 3 solid CALayer objects that fill the view, and 4 additional CALayer objects that draw the rounded edge image in each corner.

CALayer objects were used instead of UIView to avoid UITableViewCell's implicit behaviour of making backgroundView subviews transparent when tapped, and the laying out of a grid of layers was to ensure only the elements in the corner needed alpha-blending (For performance reasons).

Contributing

This view is still very much in its infancy, and a lot of it hasn't been tested beyond what's in the example app. If you have a specific use case for this view, or an idea to make it better, I'd love to hear about it. Please file an issue outlining it, and if you're up for filing a PR, that would be fantastic.

Why build this?

Since a similar style of UITableView has been prevalent in Settings.app on iPad since 2013, I'd always assumed that it was relatively trivial to modify a table view to that style if ever needed.

That assumption was put to the test one week back in 2016 when I needed to create a login view controller for a test app I was building at work. It turns out that assumption was very wrong and overriding UITableView's edge-to-edge design scheme is actually incredibly difficult.

Given the time constraints at work, I came up with a 'compromise' that let me deliver the code on time, but I was left being really curious to see if this sort of table view style could actually be done 'properly'.

So I decided to spend several evenings this past week to implement a more elegant version of the same idea.

It turns out it really isn't easy. UITableView tries to reset its UI on every tick of layoutSubviews, and UITableViewCell has a lot of implicit behaviour that messed with the 'cap' background views.

In any case, after much perseverance I'm really happy I managed to get it working to a point where it's indistinguishable from the Settings.app table view. It's this sort of thrill I absolutely love in programming. :D

Credits

TORoundedTableView was created by Tim Oliver as an experiment in insanity of reliably hacking UITableView.

iPhone XR device mockup by Pixeden.

License

TORoundedTableView is available under the MIT license. Please see the LICENSE file for more information. analytics

Comments
  • The header moves strangely when showing/hiding keyboard

    The header moves strangely when showing/hiding keyboard

    Hardware / Software

    I'm trying latest TORoundedTableViewExample. I'm using iOS 10.3.1 simulator.

    Goals

    I want to implement a setting screen like iOS. And I want to enter text in a cell.

    Expected Results

    The header and footer do not move even if showing/hiding keyboard.

    Actual Results

    gif

    Steps to Reproduce

    Add textField to cell. And showing/hiding keyboard.

    bug 
    opened by yoonchulkoh 2
  • Corner images fail to load under certain scenarios

    Corner images fail to load under certain scenarios

    We ran into an edge case in our use of TORoundedTableView (which is awesome, by the way):

    If -[TORoundedTableView layoutSubviews] is called before the table view has been added to the view hierarchy, then the rounded corner images are not loaded in time, and the table view cells do not have a rounded corner appearance.

    Why does this happen? Well, -[TORoundedTableView layoutSubviews] results in a call to -[TORoundedTableViewCapCell didMoveToSuperview]. When TORoundedTableViewCapCell tries to get the table view's roundedCornerImage in -[TORoundedTableViewCapCell didMoveToSuperview], it won't be able to because the table view hasn't loaded them yet (which happens only once the table has been added to the view hierarchy in -[TORoundedTableView didMoveToSuperview]).

    My suggested fix is to eagerly call loadCornerImages inside of -[TORoundedTableView setUp], rather than lazily in -[TORoundedTableView didMoveToSuperview]. This solved the problem for us.

    The question you're probably asking is, why would layoutSubviews be called before the table is added to the view hierarchy? We ran into a situation where we have a table header view that is sized using auto layout and, in order for it to display correctly when the table first appears, we have to call -[UITableView layoutIfNeeded] inside our view controller's viewDidLoad method. This triggers all of the layout, even though the table view doesn't have a superview yet.

    Thanks for considering this fix.

    opened by jhammer 2
  • Bump Version

    Bump Version

    Could you possible bump the version number?

    I am unable to pick up the lastest change (crashing on empty sections) without adding the following to my pod file

    pod 'TORoundedTableView', :git => 'https://github.com/TimOliver/TORoundedTableView.git', :branch => 'master'

    opened by multinerd 1
  • Fixed the bug may cause crash

    Fixed the bug may cause crash

    When indexPathsForVisibleRows is empty, call the follow method will crash on iOS 13: [self reloadRowsAtIndexPaths:self.indexPathsForVisibleRows withRowAnimation:UITableViewRowAnimationNone]

    opened by zhubinchen 1
  • Add support for iPhone XS Max and iPhone XR

    Add support for iPhone XS Max and iPhone XR

    The iPhone XS Max, and iPhone XR both support regular size class rotations in apps, just like the iPhone Plus models.

    TORoundedTableView doesn't currently support horizontal safeAreaInsets, so it's presently broken on these devices.

    This should be an easy fix. I just need to find some time. 😅

    screen shot 2018-10-29 at 11 42 38 bug 
    opened by TimOliver 1
  • Moved to Centralized Build Pipeline

    Moved to Centralized Build Pipeline

    To avoid having millions of Fastfiles, I've linked this repo to the shared Fastfile in my CI repo and hopefully haven't broken anything in the process.

    opened by TimOliver 0
  • Add full support for iOS 13

    Add full support for iOS 13

    Adds support for iOS 13.

    • Dynamic colors for dark mode.
    • Fixed some layout bugs in landscape.
    • Fixed some Core Animation glitches in moving between the modes
    opened by TimOliver 0
  • Change the default behaviour to always be visible

    Change the default behaviour to always be visible

    After seeing how common this effect became on iOS 13, it doesn't seem to be unacceptable to have rounded corners on screen sizes as small as iPhone SE anymore.

    This PR will make the effect always on, with the optional setting to turn it off.

    opened by TimOliver 0
  • Take 2 at framework scheme support

    Take 2 at framework scheme support

    This re-adds the framework support (and makes the example compile using the resulting framework rather than inline inclusion of the source); also shares the framework's scheme so that the project is usable with Carthage.

    opened by dhmspector 0
Releases(0.2.1)
  • 0.2.1(Mar 20, 2020)

  • 0.2.0(Jul 7, 2019)

    Enhancements

    • Made the effect always on by default, adding showRoundedCorners to turn it off. (#7)
    • Added iOS 13 support, including layout improvements and dark mode support. (#8)

    Changed

    • Corner radius is now 7 by default to more closely match iOS 13's design. (#7)
    • To accomodate smaller screens, the default inset is now 18. (#7)
    Source code(tar.gz)
    Source code(zip)
  • 0.1.5(Mar 17, 2019)

  • 0.1.4(Mar 17, 2019)

    Enhancements

    • Added support for devices horizontal safe insets, such as iPhone XS Max.

    Fixed

    • Updated project for Xcode 10.
    • Swapped out Travis CI for XD-CI.
    Source code(tar.gz)
    Source code(zip)
Owner
Tim Oliver
Gamer. Developer. Geek. Senior Software Engineer at @Drivemode (prev. @Realm). Lover of writing iOS code and singer of bad karaoke. 日本語もオッケ〜
Tim Oliver
HoverConversion realized vertical paging with UITableView. UIViewController will be paged when reaching top or bottom of UITableView contentOffset.

HoverConversion ManiacDev.com referred. https://maniacdev.com/2016/09/hoverconversion-a-swift-ui-component-for-navigating-between-multiple-table-views

Taiki Suzuki 166 Feb 1, 2022
Settings screen composing framework

THIS PROJECT IS NO LONGER MAINTAINED. HERE ARE SOME SUITABLE ALTERNATIVES: SwiftUI Form https://github.com/xmartlabs/Eureka https://github.com/neoneye

David Roman 1.3k Dec 25, 2022
INTUZ is presenting an interesting a Multilevel Expand/Collapse UITableView App Control to integrate inside your native iOS-based application

INTUZ is presenting an interesting a Multilevel Expand/Collapse UITableView App Control to integrate inside your native iOS-based application. MultilevelTableView is a simple component, which lets you use the tableview with multilevel tree view in your project.

INTUZ 3 Oct 3, 2022
A PageView, which supporting scrolling to transition between a UIView and a UITableView

YXTPageView ##A Page View, which support scrolling to transition between a UIView and a UITableView UIView (at the top) UITableView (at the bottom) In

Hanton Yang 68 May 25, 2022
A declarative api for working with UITableView.

⚡️ Lightning Table Lightning Table provides a powerful declarative API for working with UITableView's. Table views are the foundation of almost every

Electric Kangaroo 28 Aug 25, 2021
Simple and beautiful stacked UIView to use as a replacement for an UITableView, UIImageView or as a menu

VBPiledView simple but highly effective animation and interactivity! By v-braun - viktor-braun.de. Preview Description Very simple and beautiful stack

Viktor Braun 168 Jan 3, 2023
A pixel perfect replacement for UITableView section index, written in Swift

MYTableViewIndex MYTableViewIndex is a re-implementation of UITableView section index. This control is usually seen in apps displaying contacts, track

Yury 520 Oct 27, 2022
Easy UITableView drag-and-drop cell reordering

SwiftReorder NOTE: Some users have encountered compatibility issues when using this library with recent versions of iOS. For apps targeting iOS 11 and

Adam Shin 378 Dec 13, 2022
A cells of UITableView can be rearranged by drag and drop.

TableViewDragger This is a demo that uses a TableViewDragger. Appetize's Demo Requirements Swift 4.2 iOS 8.0 or later How to Install TableViewDragger

Kyohei Ito 515 Dec 28, 2022
A simpler way to do cool UITableView animations! (╯°□°)╯︵ ┻━┻

TableFlip (╯°□°)╯︵ ┻━┻ ┬──┬ ノ( ゜-゜ノ) Animations are cool. UITableView isn't. So why not make animating UITableView cool? The entire API for TableFlip

Joe Fabisevich 555 Dec 9, 2022
Protocol-oriented UITableView management, powered by generics and associated types.

DTTableViewManager Features Powerful mapping system between data models and cells, headers and footers Automatic datasource and interface synchronizat

Denys Telezhkin 454 Nov 9, 2022
A UITableView extension that enables cell insertion from the bottom of a table view.

ReverseExtension UITableView extension that enabled to insert cell from bottom of tableView. Concept It is difficult to fill a tableview content from

Taiki Suzuki 1.7k Dec 15, 2022
Simple single-selection or multiple-selection checklist, based on UITableView

SelectionList Simple single-selection or multiple-selection checklist, based on UITableView. Usage let selectionList = SelectionList() selectionList.i

Yonat Sharon 111 Oct 6, 2022
A declarative wrapper approach to UITableView

Thunder Table Thunder Table is a useful framework which enables quick and easy creation of table views in iOS, making the process of creating complex

3 SIDED CUBE 20 Aug 25, 2022
Convenient UITableViewCell subclass that implements a swippable content to trigger actions (similar to the Mailbox app).

MCSwipeTableViewCell An effort to show how one would implement a UITableViewCell like the one we can see in the very well executed Mailbox iOS app. Pr

Ali Karagoz 3k Dec 16, 2022
An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.

MGSwipeTableCell MGSwipeTableCell is an easy to use UITableViewCell subclass that allows to display swipeable buttons with a variety of transitions. T

Imanol Fernandez 7k Dec 26, 2022
An easy-to-use UITableViewCell subclass that implements a swippable content view which exposes utility buttons (similar to iOS 7 Mail Application)

SWTableViewCell An easy-to-use UITableViewCell subclass that implements a swipeable content view which exposes utility buttons (similar to iOS 7 Mail

Christopher Wendel 7.2k Dec 31, 2022
UIViewController subclass inspired by "Inbox by google" animated transitioning.

SAInboxViewController SAInboxViewController realizes Inbox like view transitioning. You can launch sample project on web browser from here. Features I

Taiki Suzuki 298 Jun 29, 2022
ClassicPhotos is a TableView App demos how to optimize image download and filter with operation queue.

ClassicPhotos ClassicPhotos is a TableView App demos how to optimize image download and filter with operation queue. With Operation and Operation Queu

Kushal Shingote 2 Dec 18, 2021