• Stars
    star
    160
  • Rank 227,512 (Top 5 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

TOCropViewController

A view controller for iOS that allows users to crop portions of UIImage objects
Objective-C
4,571
star
2

TOWebViewController

A view controller class for iOS that allows users to view web pages directly within an app.
Objective-C
1,490
star
3

TORoundedButton

A high-performance button control with rounded corners for iOS.
Objective-C
481
star
4

PassKit-Business-Card

A template for iOS Wallet passes that can be used like business cards.
Objective-C
387
star
5

TOPasscodeViewController

A modal passcode input and validation view controller for iOS
Objective-C
383
star
6

TONavigationBar

Replicating the 'clear' navigation bar style of the iOS 12 Apple TV app.
Objective-C
248
star
7

TOStatusBarSimulator

Replaces the iOS system status bar with a configurable mockup for the purpose of marketing screenshots.
Objective-C
199
star
8

TOSegmentedControl

A segmented control in the style of iOS 13 compatible with previous versions of iOS.
Objective-C
195
star
9

TOGlintyStringView

A non-App Store safe re-implementation of the 'slide to unlock' visual effect on iOS.
Objective-C
186
star
10

TOSMBClient

An Objective-C binding around the libDSM SMB client library.
Objective-C
177
star
11

TOActionSheet

A custom-designed reimplementation of the UIActionSheet control for iOS
Objective-C
173
star
12

RealmBrowser-iOS

A native iOS debugging framework for introspecting Realm files on device
Objective-C
148
star
13

TOSearchBar

A basic reimplementation of UISearchBar with easier theming, and nicer animation.
Objective-C
104
star
14

TOScrollBar

An interactive scroll bar for traversing comically massive scroll views.
Objective-C
91
star
15

PHP-Framework-Classes

A collection of PHP classes I've developed for personal projects.
PHP
83
star
16

TOInsetGroupedTableView

An iOS 11 back-port of the grouped inset table view style in iOS 13.
Objective-C
79
star
17

TODocumentPickerViewController

An open-source implementation for picking files/folders out of an online API
Objective-C
78
star
18

WebPKit

A framework that extends a variety of Cocoa APIs with capabilities for encoding and decoding WebP files for all of Apple's platforms.
Swift
67
star
19

TOSplitViewController

A split view controller that can display up to three view controllers at once.
Objective-C
60
star
20

Beeline

An extremely lean implementation on the classic iOS router pattern.
Swift
59
star
21

TOFileSystemObserver

A bullet-proof mechanism for detecting any changes made to the contents of a folder in iOS and macOS.
Objective-C
38
star
22

TOAlertViewController

A modern looking modal popup UI component for iOS and iPadOS.
Objective-C
24
star
23

TOAppSettings

An object wrapper for storing properties in NSUserDefaults.
Objective-C
24
star
24

TOAppRater

A very small library to provide a classier way of requesting app reviews.
Objective-C
21
star
25

TOReachability

A lightweight, unit-tested class that detects network status changes on iOS.
Objective-C
20
star
26

TOBrowserActivityKit

A set of UIActivity subclasses for opening NSURL objects in Chrome or Safari.
Objective-C
20
star
27

WebP-Cocoa

An unofficial collection of precompiled WebP binaries for all of Apple's current platforms.
Shell
18
star
28

BuildingHighPerformanceListsAndCollectionViews

A mirror of Apple's sample code for high performance collection views in iOS 15.
Swift
18
star
29

TOBadgeView

A badge view that can be used to accessorize other UI elements in iOS.
Objective-C
16
star
30

TOPagingView

A paging scroll view that can handle arbitrary numbers of page views at run-time.
Objective-C
14
star
31

TOBorderView

A flexible container view featuring a solid background with rounded corners.
Objective-C
14
star
32

TOGridView

A lightweight collection view for iOS
Objective-C
13
star
33

TORevealViewController

An alternative to UISplitViewController on both iPhone and iPad
Objective-C
11
star
34

TORoundedWindow

A UIWindow overlay that adds rounded corners to an iOS app display region
Objective-C
10
star
35

TOSegmentedTabBarController

A splittable tab bar controller controlled by a segmented control view.
Objective-C
9
star
36

TOWebContentViewController

A view controller to quickly render arbitrary local HTML content.
Objective-C
9
star
37

TODocumentsDirectoryWatcher

Automatically observes an iOS app's Documents directory for file changes.
Objective-C
8
star
38

TOPagerView

A UIScrollView subclass that allows paged horizontal swiping with a re-use mechansim similar to UITableView.
Objective-C
8
star
39

TOSegmentedSplitViewController

A split view controller that is controlled by a segmented control on small devices
Objective-C
8
star
40

TOFileKit

Not ambitious at all.
Objective-C
7
star
41

AVRecorder

A mirror of the AVRecorder sample app for macOS by Apple
Objective-C
7
star
42

TOTabBarController

A tab bar controller that mimics the vertical tool bar style of Tweetbot 4.
Objective-C
7
star
43

PhotoSorter

A quick and dirty CLI tool for sorting my photo library
Swift
7
star
44

YozoraRedux

My personal color theme I use in Xcode. Tweaked from Yozora and Sublime Text.
7
star
45

LargeImageDownsizing

Mirror of Apple's sample code for partially decoding regions of images into memory
Objective-C
6
star
46

RLMFastImage

A prototype for storing raw pixel data in Realm.
Objective-C
6
star
47

WebServerKit

A fork of the #1 HTTP server for iOS, macOS & tvOS
Objective-C
5
star
48

BTLE-Transfer

A mirror of the Apple sample code that demonstrates how to work with Core Bluetooth
Objective-C
5
star
49

TOFileAttributes

A Realm-like dynamic property wrapper that maps to APFS extended file attributes.
Objective-C
5
star
50

Spackle

A collection of convenience properties and extensions for laying out views in UIKit
Swift
5
star
51

UIColor-LegacySemanticColors

A UIColor category that backports the new semantic colors of iOS 13 to iOS 12.
Objective-C
5
star
52

SLVolumeButtonListener

A class for iOS that lets apps intercept events from the device's volume buttons
Objective-C
4
star
53

TimOliver

My GitHub README.md repository. Feel free to copy and re-use this as a template for your own GitHub account! 😁
4
star
54

TOLocalServiceDiscovery

A wrapper for detecting accessible devices locally via Bonjour.
Objective-C
4
star
55

AnimeLabPiP

A Safari Extension to enable Picture-in-Picture with AnimeLab's web player.
JavaScript
4
star
56

TOTARArchive

A basic library to allow streaming data out of TAR files
Objective-C
3
star
57

TOStackView

A barebones container view for UIKit that stacks collections of subviews
Objective-C
3
star
58

icomics.co

The source code to the official iComics website.
PHP
3
star
59

CI

A central repo for the build scripts used for testing and deploying my projects
Ruby
3
star
60

TOPropertyAccessor

Swift Property Wrappers, but in Objective-C. And done horribly.
Objective-C
3
star
61

simple-iphone-image-processing

Automatically exported from code.google.com/p/simple-iphone-image-processing
Objective-C++
2
star
62

CloudKit-PHP

For server-to-server comms from PHP to CloudKit.
PHP
2
star
63

UIDevice-UserInterfaceExtendedIdiom

An Objective-C category to allow easier detection of newer iOS device UI idioms (such as iPhone 5).
Objective-C
2
star
64

vCard

The source code to my online vCard site.
PHP
2
star
65

Dexter

An extensible encyclopedia engine
1
star
66

rchat

Swift
1
star
67

SteamAppCatalog

A dump of all of the JSON files extracted from Steam's store
1
star
68

SteamLibraryDatabase

A small utility to copy the entire Steam game library to a Realm database.
Objective-C
1
star
69

ObjC-WebPImage

An Objective-C framework for encoding and decoding WebP image files
Objective-C
1
star