Skip to content

Commit

Permalink
Added cool demo and fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
graetzer committed Jun 11, 2012
1 parent 1c2983a commit 638d1ec
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 160 deletions.
14 changes: 11 additions & 3 deletions Demo/SGTabs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
F450946C15856EC800B7B1C6 /* cross.png in Resources */ = {isa = PBXBuildFile; fileRef = F450946B15856EC800B7B1C6 /* cross.png */; };
F470D27F1580EA5100ED3644 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F470D27E1580EA5100ED3644 /* UIKit.framework */; };
F470D2811580EA5100ED3644 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F470D2801580EA5100ED3644 /* Foundation.framework */; };
F470D2831580EA5100ED3644 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F470D2821580EA5100ED3644 /* CoreGraphics.framework */; };
Expand All @@ -22,6 +23,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
F450946B15856EC800B7B1C6 /* cross.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = cross.png; sourceTree = "<group>"; };
F470D27A1580EA5100ED3644 /* SGTabs.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SGTabs.app; sourceTree = BUILT_PRODUCTS_DIR; };
F470D27E1580EA5100ED3644 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
F470D2801580EA5100ED3644 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand All @@ -41,16 +43,17 @@
F470D2AB1580ECDB00ED3644 /* SGTabsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGTabsView.m; sourceTree = "<group>"; };
F470D2AD1580ECE700ED3644 /* SGTabView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGTabView.h; sourceTree = "<group>"; };
F470D2AE1580ECE700ED3644 /* SGTabView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGTabView.m; sourceTree = "<group>"; };
F470D2B01580ED3000ED3644 /* SGToolbar.h */ = {isa = PBXFileReference; fileEncoding = 4; path = SGToolbar.h; sourceTree = "<group>"; };
F470D2B01580ED3000ED3644 /* SGToolbar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGToolbar.h; sourceTree = "<group>"; };
F470D2B11580ED3000ED3644 /* SGToolbar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGToolbar.m; sourceTree = "<group>"; };
F476BFBF15816C8E00BABEEB /* SGTabView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGTabView.h; sourceTree = "<group>"; };
F476BFC015816C8E00BABEEB /* SGTabView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGTabView.m; sourceTree = "<group>"; };
F476BFC115816C8E00BABEEB /* SGToolbar.h */ = {isa = PBXFileReference; fileEncoding = 4; path = SGToolbar.h; sourceTree = "<group>"; };
F476BFC215816C8E00BABEEB /* SGToolbar.m */ = {isa = PBXFileReference; fileEncoding = 4; path = SGToolbar.m; sourceTree = "<group>"; };
F476BFC115816C8E00BABEEB /* SGToolbar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGToolbar.h; sourceTree = "<group>"; };
F476BFC215816C8E00BABEEB /* SGToolbar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGToolbar.m; sourceTree = "<group>"; };
F476BFC315816C8E00BABEEB /* SGTabsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGTabsView.h; sourceTree = "<group>"; };
F476BFC415816C8E00BABEEB /* SGTabsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGTabsView.m; sourceTree = "<group>"; };
F476BFC515816C8E00BABEEB /* SGTabsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SGTabsViewController.h; sourceTree = "<group>"; };
F476BFC615816C8E00BABEEB /* SGTabsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SGTabsViewController.m; sourceTree = "<group>"; };
F493636B158686E200FBD5F3 /* SGTabDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SGTabDefines.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -124,6 +127,7 @@
F470D2A61580EAD700ED3644 /* Source */ = {
isa = PBXGroup;
children = (
F450946B15856EC800B7B1C6 /* cross.png */,
F470D2A71580EAD700ED3644 /* SGTabsViewController.h */,
F470D2A81580EAD700ED3644 /* SGTabsViewController.m */,
F470D2AA1580ECDB00ED3644 /* SGTabsView.h */,
Expand All @@ -132,6 +136,7 @@
F470D2AE1580ECE700ED3644 /* SGTabView.m */,
F470D2B01580ED3000ED3644 /* SGToolbar.h */,
F470D2B11580ED3000ED3644 /* SGToolbar.m */,
F493636B158686E200FBD5F3 /* SGTabDefines.h */,
);
name = Source;
path = ../Source;
Expand Down Expand Up @@ -207,6 +212,7 @@
files = (
F470D2891580EA5100ED3644 /* InfoPlist.strings in Resources */,
F470D2951580EA5100ED3644 /* SGViewController.xib in Resources */,
F450946C15856EC800B7B1C6 /* cross.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -303,6 +309,7 @@
GCC_PREFIX_HEADER = "SGTabs/SGTabs-Prefix.pch";
INFOPLIST_FILE = "SGTabs/SGTabs-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 2;
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -314,6 +321,7 @@
GCC_PREFIX_HEADER = "SGTabs/SGTabs-Prefix.pch";
INFOPLIST_FILE = "SGTabs/SGTabs-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 2;
WRAPPER_EXTENSION = app;
};
name = Release;
Expand Down
1 change: 0 additions & 1 deletion Demo/SGTabs/SGAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
@class SGTabsViewController;

@interface SGAppDelegate : UIResponder <UIApplicationDelegate> {
NSTimer *timer;
}

@property (strong, nonatomic) UIWindow *window;
Expand Down
24 changes: 8 additions & 16 deletions Demo/SGTabs/SGAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,24 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
// self.viewController = [[SGViewController alloc] initWithNibName:@"SGViewController_iPhone" bundle:nil];
// } else {
// self.viewController = [[SGViewController alloc] initWithNibName:@"SGViewController_iPad" bundle:nil];
// }

self.tabController = [[SGTabsViewController alloc] initEditable:YES];
self.window.rootViewController = self.tabController;
[self.window makeKeyAndVisible];

[self openTab];
timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(openTab) userInfo:nil repeats:YES];

[self performSelector:@selector(openTab) withObject:nil afterDelay:1];

return YES;
}

- (void)openTab {
if (4 > self.tabController.count) { // You can add up to tabController.maxCount Tabs
SGViewController *vc = [[SGViewController alloc]
initWithNibName:NSStringFromClass([SGViewController class])
bundle:nil];
vc.title = [NSString stringWithFormat:@"Tab %i content", self.tabController.count+1];
[self.tabController addTab:vc];
} else if (self.tabController.count == 4){
[self.tabController setToolbarHidden:NO animated:YES];
}
[self.tabController setToolbarHidden:NO animated:YES];
SGViewController *vc = [[SGViewController alloc]
initWithNibName:NSStringFromClass([SGViewController class])
bundle:nil];
vc.title = [NSString stringWithFormat:@"Tab %i content", self.tabController.count+1];
[self.tabController addTab:vc];
}

@end
34 changes: 34 additions & 0 deletions Demo/SGTabs/SGViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ - (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.label.text = self.title;

UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
UIBarButtonItem *trash = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
target:self
action:@selector(remove:)];
UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(add:)];
self.toolbarItems = [NSArray arrayWithObjects:space, trash, add, nil];
}

- (void)viewDidUnload
Expand All @@ -43,6 +53,14 @@ - (void)viewDidUnload
// Release any retained subviews of the main view.
}

- (void)viewWillDisappear:(BOOL)animated {
NSLog(@"viewWillDisappear");
}

- (void)viewDidDisappear:(BOOL)animated {
NSLog(@"ViewDidDisappear");
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
Expand All @@ -51,5 +69,21 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return YES;
}
}

- (IBAction)remove:(id)sender {
SGTabsViewController *tabs = (SGTabsViewController *) self.parentViewController;
[tabs removeViewController:self];
}

- (IBAction)add:(id)sender {
SGTabsViewController *tabs = (SGTabsViewController *) self.parentViewController;

SGViewController *vc = [[SGViewController alloc]
initWithNibName:NSStringFromClass([SGViewController class])
bundle:nil];
vc.title = [NSString stringWithFormat:@"Tab %i content", tabs.count+1];
[tabs addTab:vc];

}

@end
31 changes: 29 additions & 2 deletions Demo/SGTabs/en.lproj/SGViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
<object class="IBUILabel" id="638580792">
<reference key="NSNextResponder" ref="774585933"/>
<int key="NSvFlags">274</int>
<string key="NSFrame">{{77, 83}, {167, 142}}</string>
<string key="NSFrame">{{77, 159}, {167, 142}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
Expand All @@ -54,6 +56,7 @@
<nil key="IBUIHighlightedColor"/>
<int key="IBUIBaselineAdjustment">0</int>
<float key="IBUIMinimumFontSize">10</float>
<int key="IBUITextAlignment">1</int>
<object class="IBUIFontDescription" key="IBUIFontDescription">
<int key="type">1</int>
<double key="pointSize">35</double>
Expand All @@ -67,6 +70,8 @@
</array>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="638580792"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
Expand Down Expand Up @@ -143,7 +148,29 @@
<nil key="sourceID"/>
<int key="maxID">10</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes"/>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">SGViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">label</string>
<string key="NS.object.0">UILabel</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">label</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">label</string>
<string key="candidateClassName">UILabel</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/SGViewController.h</string>
</object>
</object>
</array>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# SGTabs

Tab component for iOS 5+. You can show your ViewControllers in tabs, it is possible to add and remove tabs on the fly
Tab component for iOS 5+. You can show your ViewControllers in tabs, it is possible to add and remove tabs on the fly.

# Features
- Uses iOS 5 UIViewController Container API
- Add and remove tabs on the fly with animations
- User can remove tabs by pressing an X on a tab. TODO
- Dynamically show and hide a UIToolbar at the top
- Show the UIBarButtonItems in viewController.toolbarItems in the toolbar
- It should be possible to create Safari style apps

# Screenshots

![Multiple Tabs open][screen.png "Multiple Tabs open"]

![Toolbar visible][screen_Toolbar.png "A Toolbar with one element visible"]



Expand Down
41 changes: 41 additions & 0 deletions Source/SGTabDefines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// SGTabDefines.h
// SGTabs
//
// Created by simon on 11.06.12.
//
//
// Copyright (c) 2012 Simon Grätzer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef SGTabs_SGTabConstants_h
#define SGTabs_SGTabConstants_h

#define kAddTabDuration 0.4
#define kRemoveTabDuration 0.4

#define kTabsToolbarHeigth 10.0
#define kTabsToolbarHeigthFull 44.0
#define kTabsHeigth 30.0

#define kCornerRadius 7.5

#define kShadowRadius 6.0

#define kTabColor [[UIColor alloc] initWithWhite:0.85 alpha:1]
#define kTabUnselectedColor [[UIColor alloc] initWithWhite:0.7 alpha:1]
//[[UIColor alloc] initWithWhite:0.6 alpha:1]

#endif
8 changes: 3 additions & 5 deletions Source/SGTabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@

#import <UIKit/UIKit.h>

@interface SGTabView : UIView {
UIColor *topColor;
UIColor *bottomColor;
}
@interface SGTabView : UIView

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *closeButton;
@property (nonatomic, assign) BOOL editable;

@property (nonatomic, strong) UIColor *tabColor;

- (id)initWithFrame:(CGRect)frame title:(NSString *)title;

Expand Down
Loading

0 comments on commit 638d1ec

Please sign in to comment.