Git Product home page Git Product logo

trtabview's Introduction

TRTabView

What it is

TRTabView is a tab view as seen in Mobile Safari for iPad, using the familiar delegate/data source design pattern known from UITableView.

screencast

Overview

TRTabView uses a delegate design pattern that is inspired by the UITableView delegate and data source methods.

Tab reordering, overflow behavior, the minimum/maximum number of tabs, the minimum/maximum tab widths and much more are easy configurable by implementing the corresponding delegate calls.

For most settings there is a reasonable default already provided.

Display orientation changes are supported out of the box.

See https://github.com/mkeiser/TRTabView for an example project.

View setup

The actual TRTabView is only the area that contains the tabs. It can be added freely to any superview. It does not manage the actual content you want to display for each tab. So what actually happens when a tab is selected is entirely up to you.

The project contains the TRTabViewToolbar class (a subclass of UIToolbar) which should be placed above the tab view to form its upper area (the "roots" of the tabs). However, apart from drawing a background that matches the tab bar, it does not have any special functionality. One could also use a UINavigationBar subclass or a custom view instead.

View Layout

How to use

Create a TRTabView and assign a delegate to it that conforms to the TRTabViewDelegate protocol.

A minimal delegate implementation looks something like this:

/* Assume "self.model" holds an array of strings that represent the tab titles. */

- (NSUInteger)numberOfTabsInTabView:(TRTabView *)tabView {

	return [self.model count];
}

- (TRTab *)tabView:(TRTabView *)tabView tabForIndex:(NSUInteger)index {

	TRTab *tab = [tabView dequeueDefaultTabForIndex:index]; // Use default tab views
	tab.titleLabel.text = [self.model objectAtIndex:index];

	return tab;
}

/* Return the title to use in the overflow popover. */

- (NSString *)overflowTitleForIndex:(NSUInteger)index {

	return [self.model objectAtIndex:index];
}

- (void)tabView:(TRTabView *)tabView didSelectTabAtIndex:(NSUInteger)index {

	id modelObject = self.model[index];

	/* Display content view for model object */
}

When you show the add button (tabView.showAddButton = YES), you should implement a method to handle tab additions:

- (void)tabViewCommitTabAddition:(TRTabView *)tabView {

	id modelObject = new model object...
	NSUInteger index = new model object index...
	[self.model insertObject:modelObject atIndex:index];

	[tabView addTabAtIndex:index animated:YES];
}

If you enable tab deletion (tabView.deleteButtonMode != TRTabViewButtonModeNever), you need to handle tab deletion:

- (void)tabView:(TRTabView *)tabView commitTabDeletionAtIndex:(NSUInteger)index {

	[self.model removeObjectAtIndex:index];

	[self.tabView deleteTabAtIndex:index animated:YES];
}

TRTabView is quite flexible and offers many ways to customize its behaviour. Please check the header files for addtional methods and properties.

License

MIT

Contact

[email protected]

tristan-inc.com

github.com/mkeiser

trtabview's People

Contributors

mkeiser avatar seijiito avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.