Skip to content

Commit

Permalink
Refactored and fixed issues with viewpager
Browse files Browse the repository at this point in the history
  • Loading branch information
pplant committed Apr 28, 2016
1 parent be37b04 commit 46059db
Show file tree
Hide file tree
Showing 21 changed files with 455 additions and 816 deletions.
55 changes: 36 additions & 19 deletions ICViewPager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 47;
objects = {

/* Begin PBXBuildFile section */
7C115E011816DED1000BCE63 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7C115E001816DED1000BCE63 /* Images.xcassets */; };
7CEC17A917DA1EC000E4A439 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7CEC17A817DA1EC000E4A439 /* iPad.storyboard */; };
7CF3D65517CE32E40021036A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7CF3D65417CE32E40021036A /* UIKit.framework */; };
7CF3D65717CE32E40021036A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7CF3D65617CE32E40021036A /* Foundation.framework */; };
7CF3D65917CE32E40021036A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7CF3D65817CE32E40021036A /* CoreGraphics.framework */; };
7CF3D65F17CE32E40021036A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7CF3D65D17CE32E40021036A /* InfoPlist.strings */; };
7CF3D66117CE32E40021036A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CF3D66017CE32E40021036A /* main.m */; };
7CF3D66517CE32E40021036A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CF3D66417CE32E40021036A /* AppDelegate.m */; };
7CF3D67617CE336E0021036A /* Localization.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7CF3D67817CE336E0021036A /* Localization.strings */; };
7CF3D67E17CE33E10021036A /* ViewPagerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CF3D67D17CE33E10021036A /* ViewPagerController.m */; };
7CF3D67E17CE33E10021036A /* ICViewPagerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CF3D67D17CE33E10021036A /* ICViewPagerController.m */; };
7CF3D68117CE33EC0021036A /* HostViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CF3D68017CE33EC0021036A /* HostViewController.m */; };
7CF3D68217CE35500021036A /* iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7CF3D67117CE332F0021036A /* iPhone.storyboard */; };
7CF3D68517CE3F5B0021036A /* ContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CF3D68417CE3F5B0021036A /* ContentViewController.m */; };
D08D962B1CD1FA8900B22AE8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D08D962A1CD1FA8900B22AE8 /* LaunchScreen.storyboard */; };
D08D962E1CD1FCA300B22AE8 /* UIColor+Equality.m in Sources */ = {isa = PBXBuildFile; fileRef = D08D962D1CD1FCA300B22AE8 /* UIColor+Equality.m */; };
D08D96311CD200A200B22AE8 /* ICTabView.m in Sources */ = {isa = PBXBuildFile; fileRef = D08D96301CD200A200B22AE8 /* ICTabView.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
7C115E001816DED1000BCE63 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
7CEC17A817DA1EC000E4A439 /* iPad.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = iPad.storyboard; sourceTree = "<group>"; };
7CF3D65117CE32E40021036A /* ICViewPager.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ICViewPager.app; sourceTree = BUILT_PRODUCTS_DIR; };
7CF3D65417CE32E40021036A /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
7CF3D65617CE32E40021036A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand All @@ -39,12 +40,17 @@
7CF3D67317CE335B0021036A /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/InfoPlist.strings; sourceTree = "<group>"; };
7CF3D67717CE336E0021036A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localization.strings; sourceTree = "<group>"; };
7CF3D67917CE336F0021036A /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/Localization.strings; sourceTree = "<group>"; };
7CF3D67C17CE33E10021036A /* ViewPagerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewPagerController.h; sourceTree = "<group>"; };
7CF3D67D17CE33E10021036A /* ViewPagerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewPagerController.m; sourceTree = "<group>"; };
7CF3D67C17CE33E10021036A /* ICViewPagerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ICViewPagerController.h; sourceTree = "<group>"; };
7CF3D67D17CE33E10021036A /* ICViewPagerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ICViewPagerController.m; sourceTree = "<group>"; };
7CF3D67F17CE33EC0021036A /* HostViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HostViewController.h; sourceTree = "<group>"; };
7CF3D68017CE33EC0021036A /* HostViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HostViewController.m; sourceTree = "<group>"; };
7CF3D68317CE3F5B0021036A /* ContentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentViewController.h; sourceTree = "<group>"; };
7CF3D68417CE3F5B0021036A /* ContentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContentViewController.m; sourceTree = "<group>"; };
D08D962A1CD1FA8900B22AE8 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
D08D962C1CD1FCA300B22AE8 /* UIColor+Equality.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+Equality.h"; sourceTree = "<group>"; };
D08D962D1CD1FCA300B22AE8 /* UIColor+Equality.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+Equality.m"; sourceTree = "<group>"; };
D08D962F1CD200A200B22AE8 /* ICTabView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ICTabView.h; sourceTree = "<group>"; };
D08D96301CD200A200B22AE8 /* ICTabView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ICTabView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -91,10 +97,10 @@
7CF3D65A17CE32E40021036A /* ICViewPager */ = {
isa = PBXGroup;
children = (
D08D962A1CD1FA8900B22AE8 /* LaunchScreen.storyboard */,
7CF3D66317CE32E40021036A /* AppDelegate.h */,
7CF3D66417CE32E40021036A /* AppDelegate.m */,
7CF3D67117CE332F0021036A /* iPhone.storyboard */,
7CEC17A817DA1EC000E4A439 /* iPad.storyboard */,
7CF3D67B17CE33C80021036A /* ICViewPager */,
7CF3D67A17CE33C80021036A /* Controller */,
7C115E001816DED1000BCE63 /* Images.xcassets */,
Expand Down Expand Up @@ -129,8 +135,12 @@
7CF3D67B17CE33C80021036A /* ICViewPager */ = {
isa = PBXGroup;
children = (
7CF3D67C17CE33E10021036A /* ViewPagerController.h */,
7CF3D67D17CE33E10021036A /* ViewPagerController.m */,
7CF3D67C17CE33E10021036A /* ICViewPagerController.h */,
7CF3D67D17CE33E10021036A /* ICViewPagerController.m */,
D08D962F1CD200A200B22AE8 /* ICTabView.h */,
D08D96301CD200A200B22AE8 /* ICTabView.m */,
D08D962C1CD1FCA300B22AE8 /* UIColor+Equality.h */,
D08D962D1CD1FCA300B22AE8 /* UIColor+Equality.m */,
);
path = ICViewPager;
sourceTree = "<group>";
Expand Down Expand Up @@ -161,11 +171,11 @@
7CF3D64917CE32E40021036A /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0460;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = "Ilter Cengiz";
};
buildConfigurationList = 7CF3D64C17CE32E40021036A /* Build configuration list for PBXProject "ICViewPager" */;
compatibilityVersion = "Xcode 3.2";
compatibilityVersion = "Xcode 6.3";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
Expand All @@ -190,7 +200,7 @@
7CF3D65F17CE32E40021036A /* InfoPlist.strings in Resources */,
7C115E011816DED1000BCE63 /* Images.xcassets in Resources */,
7CF3D68217CE35500021036A /* iPhone.storyboard in Resources */,
7CEC17A917DA1EC000E4A439 /* iPad.storyboard in Resources */,
D08D962B1CD1FA8900B22AE8 /* LaunchScreen.storyboard in Resources */,
7CF3D67617CE336E0021036A /* Localization.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -202,9 +212,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D08D96311CD200A200B22AE8 /* ICTabView.m in Sources */,
7CF3D66117CE32E40021036A /* main.m in Sources */,
D08D962E1CD1FCA300B22AE8 /* UIColor+Equality.m in Sources */,
7CF3D66517CE32E40021036A /* AppDelegate.m in Sources */,
7CF3D67E17CE33E10021036A /* ViewPagerController.m in Sources */,
7CF3D67E17CE33E10021036A /* ICViewPagerController.m in Sources */,
7CF3D68117CE33EC0021036A /* HostViewController.m in Sources */,
7CF3D68517CE3F5B0021036A /* ContentViewController.m in Sources */,
);
Expand Down Expand Up @@ -248,6 +260,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All @@ -259,7 +272,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -284,7 +297,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -296,12 +309,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = "Brand Assets";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "ICViewPager/ICViewPager-Prefix.pch";
INFOPLIST_FILE = "ICViewPager/ICViewPager-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
PRODUCT_BUNDLE_IDENTIFIER = "info.iltercengiz.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -310,12 +325,14 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = "Brand Assets";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "ICViewPager/ICViewPager-Prefix.pch";
INFOPLIST_FILE = "ICViewPager/ICViewPager-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
PRODUCT_BUNDLE_IDENTIFIER = "info.iltercengiz.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions ICViewPager/Controller/HostViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#import <QuartzCore/QuartzCore.h>

#import "ViewPagerController.h"
#import "ICViewPagerController.h"

@interface HostViewController : ViewPagerController
@interface HostViewController : ICViewPagerController

@end
82 changes: 25 additions & 57 deletions ICViewPager/Controller/HostViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "HostViewController.h"
#import "ContentViewController.h"

@interface HostViewController () <ViewPagerDataSource, ViewPagerDelegate>
@interface HostViewController () <ICViewPagerDataSource, ICViewPagerDelegate>

@property (nonatomic) NSUInteger numberOfTabs;

Expand All @@ -23,39 +23,30 @@ - (void)viewDidLoad {

self.dataSource = self;
self.delegate = self;
self.initalIndex = 0;

self.title = @"View Pager";

// Keeps tab bar below navigation bar on iOS 7.0+
// if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
// self.edgesForExtendedLayout = UIRectEdgeNone;
// }

self.navigationItem.rightBarButtonItem = ({

UIBarButtonItem *button;
button = [[UIBarButtonItem alloc] initWithTitle:@"Tab #5" style:UIBarButtonItemStylePlain target:self action:@selector(selectTabWithNumberFive)];
button = [[UIBarButtonItem alloc] initWithTitle:@"Reduce" style:UIBarButtonItemStylePlain target:self action:@selector(reduce)];

button;
});

}
- (void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

[self performSelector:@selector(loadContent) withObject:nil afterDelay:3.0];


- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.numberOfTabs = 0;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (void) reduce{
self.numberOfTabs = 5;
}

#pragma mark - Setters
- (void)setNumberOfTabs:(NSUInteger)numberOfTabs {

// Set numberOfTabs
_numberOfTabs = numberOfTabs;

Expand All @@ -64,79 +55,56 @@ - (void)setNumberOfTabs:(NSUInteger)numberOfTabs {

}

#pragma mark - Helpers
- (void)selectTabWithNumberFive {
[self selectTabAtIndex:5];
}
- (void)loadContent {
self.numberOfTabs = 10;
}

#pragma mark - Interface Orientation Changes

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

// Update changes after screen rotates
[self performSelector:@selector(setNeedsReloadOptions) withObject:nil afterDelay:duration];
}

#pragma mark - ViewPagerDataSource
- (NSUInteger)numberOfTabsForViewPager:(ViewPagerController *)viewPager {

- (NSUInteger)numberOfTabsForViewPager:(ICViewPagerController *)viewPager {
return self.numberOfTabs;
}
- (UIView *)viewPager:(ViewPagerController *)viewPager viewForTabAtIndex:(NSUInteger)index {

- (UIView *)viewPager:(ICViewPagerController *)viewPager viewForTabAtIndex:(NSUInteger)index {

UILabel *label = [UILabel new];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:12.0];
label.text = [NSString stringWithFormat:@"Tab #%i", index];
label.text = [NSString stringWithFormat:@"Tab #%lu", (unsigned long)index];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
[label sizeToFit];

return label;
}

- (UIViewController *)viewPager:(ViewPagerController *)viewPager contentViewControllerForTabAtIndex:(NSUInteger)index {
- (UIViewController *)viewPager:(ICViewPagerController *)viewPager contentViewControllerForTabAtIndex:(NSUInteger)index {

ContentViewController *cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"contentViewController"];

cvc.labelString = [NSString stringWithFormat:@"Content View #%i", index];
cvc.labelString = [NSString stringWithFormat:@"Content View #%lu", (unsigned long)index];

return cvc;
}

#pragma mark - ViewPagerDelegate
- (CGFloat)viewPager:(ViewPagerController *)viewPager valueForOption:(ViewPagerOption)option withDefault:(CGFloat)value {

switch (option) {
case ViewPagerOptionStartFromSecondTab:
return 0.0;
case ViewPagerOptionCenterCurrentTab:
return 1.0;
case ViewPagerOptionTabLocation:
return 0.0;
case ViewPagerOptionTabHeight:
return 49.0;
case ViewPagerOptionTabOffset:
return 36.0;
case ViewPagerOptionTabWidth:
return UIInterfaceOrientationIsLandscape(self.interfaceOrientation) ? 128.0 : 96.0;
case ViewPagerOptionFixFormerTabsPositions:
return 1.0;
case ViewPagerOptionFixLatterTabsPositions:
return 1.0;
default:
return value;
}

- (CGFloat)viewPager:(ICViewPagerController *)viewPager widthForTabAtIndex:(NSUInteger)index{
return 50.0;
}
- (UIColor *)viewPager:(ViewPagerController *)viewPager colorForComponent:(ViewPagerComponent)component withDefault:(UIColor *)color {

- (UIColor *)viewPager:(ICViewPagerController *)viewPager colorForComponent:(ICViewPagerComponent)component withDefault:(UIColor *)color {

switch (component) {
case ViewPagerIndicator:
case ICViewPagerIndicator:
return [[UIColor redColor] colorWithAlphaComponent:0.64];
case ViewPagerTabsView:
case ICViewPagerTabsView:
return [[UIColor lightGrayColor] colorWithAlphaComponent:0.32];
case ViewPagerContent:
case ICViewPagerContent:
return [[UIColor darkGrayColor] colorWithAlphaComponent:0.32];
default:
return color;
Expand Down
4 changes: 3 additions & 1 deletion ICViewPager/ICViewPager-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<key>CFBundleIcons~ipad</key>
<dict/>
<key>CFBundleIdentifier</key>
<string>info.iltercengiz.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand All @@ -28,6 +28,8 @@
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>iPhone</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
16 changes: 16 additions & 0 deletions ICViewPager/ICViewPager/ICTabView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TabView.h
// ICViewPager
//
// Created by Peter Plant on 28/04/16.
// Copyright © 2016 Ilter Cengiz. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ICTabView : UIView

@property (nonatomic, getter = isSelected) BOOL selected;
@property (nonatomic) UIColor *indicatorColor;

@end
Loading

0 comments on commit 46059db

Please sign in to comment.