From 4b048721f2393b2b32373dea687800bb99243fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=93=E5=89=91=E9=94=90?= Date: Thu, 17 Dec 2015 17:29:02 +0800 Subject: [PATCH 1/2] add custom method 1. topbar item frame 2. scrollView --- DAPagesContainer/DAPagesContainer.h | 6 +++- DAPagesContainer/DAPagesContainer.m | 9 ++--- DAPagesContainer/DAPagesContainerTopBar.h | 1 + DAPagesContainer/DAPagesContainerTopBar.m | 32 ++++++++++++++---- .../project.pbxproj | 4 +++ DAPagesContainerDemo/DAViewController.m | 5 +++ indicator.png | Bin 0 -> 510 bytes 7 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 indicator.png diff --git a/DAPagesContainer/DAPagesContainer.h b/DAPagesContainer/DAPagesContainer.h index b5d31fe..4662b1e 100644 --- a/DAPagesContainer/DAPagesContainer.h +++ b/DAPagesContainer/DAPagesContainer.h @@ -7,7 +7,8 @@ // #import - +#import "DAPagesContainerTopBar.h" +#import "DAPageIndicatorView.h" @interface DAPagesContainer : UIViewController @@ -83,4 +84,7 @@ */ - (void)updateLayoutForNewOrientation:(UIInterfaceOrientation)orientation; + +@property (strong, nonatomic) DAPagesContainerTopBar *topBar; +@property (strong, nonatomic) UIScrollView *scrollView; @end \ No newline at end of file diff --git a/DAPagesContainer/DAPagesContainer.m b/DAPagesContainer/DAPagesContainer.m index 51b6627..a2ecaa4 100644 --- a/DAPagesContainer/DAPagesContainer.m +++ b/DAPagesContainer/DAPagesContainer.m @@ -8,14 +8,11 @@ #import "DAPagesContainer.h" -#import "DAPagesContainerTopBar.h" -#import "DAPageIndicatorView.h" + @interface DAPagesContainer () -@property (strong, nonatomic) DAPagesContainerTopBar *topBar; -@property (strong, nonatomic) UIScrollView *scrollView; @property (weak, nonatomic) UIScrollView *observingScrollView; @property (strong, nonatomic) UIView *pageIndicatorView; @@ -118,7 +115,7 @@ - (void)setSelectedIndex:(NSUInteger)selectedIndex animated:(BOOL)animated NSAssert(selectedIndex < self.viewControllers.count, @"selectedIndex should belong within the range of the view controllers array"); UIButton *previosSelectdItem = self.topBar.itemViews[self.selectedIndex]; UIButton *nextSelectdItem = self.topBar.itemViews[selectedIndex]; - if (abs(self.selectedIndex - selectedIndex) <= 1) { + if ( self.selectedIndex < selectedIndex || (self.selectedIndex - selectedIndex) <= 1) { [self.scrollView setContentOffset:CGPointMake(selectedIndex * self.scrollWidth, 0.) animated:animated]; if (selectedIndex == _selectedIndex) { self.pageIndicatorView.center = CGPointMake([self.topBar centerForSelectedItemAtIndex:selectedIndex].x, @@ -400,7 +397,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath [self getRed:&red green:&green blue:&blue alpha:&alpha fromColor:self.pageItemsTitleColor]; [self getRed:&highlightedRed green:&highlightedGreen blue:&highlightedBlue alpha:&highlightedAlpha fromColor:self.selectedPageItemTitleColor]; - CGFloat absRatio = fabsf(ratio); + CGFloat absRatio = fabs(ratio); UIColor *prev = [UIColor colorWithRed:red * absRatio + highlightedRed * (1 - absRatio) green:green * absRatio + highlightedGreen * (1 - absRatio) blue:blue * absRatio + highlightedBlue * (1 - absRatio) diff --git a/DAPagesContainer/DAPagesContainerTopBar.h b/DAPagesContainer/DAPagesContainerTopBar.h index 4638ad0..6d0e892 100644 --- a/DAPagesContainer/DAPagesContainerTopBar.h +++ b/DAPagesContainer/DAPagesContainerTopBar.h @@ -31,4 +31,5 @@ - (CGPoint)centerForSelectedItemAtIndex:(NSUInteger)index; - (CGPoint)contentOffsetForSelectedItemAtIndex:(NSUInteger)index; +- (void)layoutItemWithSpecifyX:(float)offectX Y:(float)offectY w:(float)width h:(float)height; @end \ No newline at end of file diff --git a/DAPagesContainer/DAPagesContainerTopBar.m b/DAPagesContainer/DAPagesContainerTopBar.m index 6c3a0ff..e7f9afa 100644 --- a/DAPagesContainer/DAPagesContainerTopBar.m +++ b/DAPagesContainer/DAPagesContainerTopBar.m @@ -9,7 +9,10 @@ #import "DAPagesContainerTopBar.h" -@interface DAPagesContainerTopBar () +@interface DAPagesContainerTopBar (){ + CGFloat ofx ,ofy ,iw,ih; + BOOL customItemFrame; +} @property (strong, nonatomic) UIImageView *backgroundImageView; @property (strong, nonatomic) UIScrollView *scrollView; @@ -35,6 +38,11 @@ - (id)initWithFrame:(CGRect)frame [self addSubview:self.scrollView]; self.font = [UIFont systemFontOfSize:14]; self.itemTitleColor = [UIColor whiteColor]; + ofx = DAPagesContainerTopBarItemsOffset; + ofy = 0; + iw = DAPagesContainerTopBarItemViewWidth; + ih = CGRectGetHeight(frame); + } return self; } @@ -105,7 +113,7 @@ - (void)setFont:(UIFont *)font - (UIButton *)addItemView { - CGRect frame = CGRectMake(0., 0., DAPagesContainerTopBarItemViewWidth, CGRectGetHeight(self.frame)); + CGRect frame = CGRectMake(0., 0., iw, CGRectGetHeight(self.frame)); UIButton *itemView = [[UIButton alloc] initWithFrame:frame]; [itemView addTarget:self action:@selector(itemViewTapped:) forControlEvents:UIControlEventTouchUpInside]; itemView.titleLabel.font = self.font; @@ -121,12 +129,15 @@ - (void)itemViewTapped:(UIButton *)sender - (void)layoutItemViews { - CGFloat x = DAPagesContainerTopBarItemsOffset; + CGFloat x = ofx; for (NSUInteger i = 0; i < self.itemViews.count; i++) { - CGFloat width = [self.itemTitles[i] sizeWithFont:self.font].width; + CGFloat width = iw; + if (!customItemFrame) { + width = [self.itemTitles[i] sizeWithFont:self.font].width; + } UIView *itemView = self.itemViews[i]; - itemView.frame = CGRectMake(x, 0., width, CGRectGetHeight(self.frame)); - x += width + DAPagesContainerTopBarItemsOffset; + itemView.frame = CGRectMake(x, ofy, width, ih); + x += width + ofx; } self.scrollView.contentSize = CGSizeMake(x, CGRectGetHeight(self.scrollView.frame)); CGRect frame = self.scrollView.frame; @@ -139,7 +150,14 @@ - (void)layoutItemViews } self.scrollView.frame = frame; } - +- (void)layoutItemWithSpecifyX:(float)offectX Y:(float)offectY w:(float)width h:(float)height{ + ofx = offectX; + ofy = offectY; + iw = width; + ih = height; + customItemFrame = YES; + [self layoutItemViews]; +} - (void)layoutSubviews { [super layoutSubviews]; diff --git a/DAPagesContainerDemo.xcodeproj/project.pbxproj b/DAPagesContainerDemo.xcodeproj/project.pbxproj index 0a3e654..8e7fe29 100644 --- a/DAPagesContainerDemo.xcodeproj/project.pbxproj +++ b/DAPagesContainerDemo.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ 43222CC71768E4D30088986F /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 43222CC41768E4D30088986F /* MainStoryboard.storyboard */; }; 438BA887175785B00033EB2D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 438BA886175785B00033EB2D /* UIKit.framework */; }; 438BA88B175785B00033EB2D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 438BA88A175785B00033EB2D /* CoreGraphics.framework */; }; + EFAB51CD1C22B4AE00F395B5 /* indicator.png in Resources */ = {isa = PBXBuildFile; fileRef = EFAB51CC1C22B4AE00F395B5 /* indicator.png */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -53,6 +54,7 @@ 438BA886175785B00033EB2D /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 438BA888175785B00033EB2D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 438BA88A175785B00033EB2D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + EFAB51CC1C22B4AE00F395B5 /* indicator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = indicator.png; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -141,6 +143,7 @@ 438BA8B6175786240033EB2D /* Images */ = { isa = PBXGroup; children = ( + EFAB51CC1C22B4AE00F395B5 /* indicator.png */, 43222CBA1768E49F0088986F /* beaver.jpg */, 43222CBB1768E49F0088986F /* buckDeer.jpg */, 43222CBC1768E49F0088986F /* cat.jpg */, @@ -206,6 +209,7 @@ 43222CB81768E48E0088986F /* Default@2x.png in Resources */, 43222CBE1768E49F0088986F /* beaver.jpg in Resources */, 43222CBF1768E49F0088986F /* buckDeer.jpg in Resources */, + EFAB51CD1C22B4AE00F395B5 /* indicator.png in Resources */, 43222CC01768E49F0088986F /* cat.jpg in Resources */, 43222CC11768E49F0088986F /* lion.jpg in Resources */, 43222CC61768E4D30088986F /* InfoPlist.strings in Resources */, diff --git a/DAPagesContainerDemo/DAViewController.m b/DAPagesContainerDemo/DAViewController.m index 0e1dbb0..3f73649 100644 --- a/DAPagesContainerDemo/DAViewController.m +++ b/DAPagesContainerDemo/DAViewController.m @@ -55,6 +55,11 @@ - (void)viewDidLoad lionViewController.title = @"REALLY CUTE LION"; self.pagesContainer.viewControllers = @[beaverViewController, buckDeerViewController, catViewController, lionViewController]; + + +// [self.pagesContainer.topBar layoutItemWithSpecifyX:0 Y:0 w:CGRectGetWidth(self.view.frame)/4 h:CGRectGetHeight(self.pagesContainer.topBar.frame)]; +// self.pagesContainer.pageIndicatorViewSize = CGSizeMake(CGRectGetWidth(self.view.frame)/4, 2); +// self.pagesContainer.pageIndicatorImage = [UIImage imageNamed:@"indicator.png"]; } - (void)viewWillUnload diff --git a/indicator.png b/indicator.png new file mode 100644 index 0000000000000000000000000000000000000000..3635a738c858e765f13f9b1193968fc5bb099d01 GIT binary patch literal 510 zcmeAS@N?(olHy`uVBq!ia0vp^0YJ>c!3HEH`F8k#IO&eQjtmSN`?>!lvI6;>1s;*b z3=G`DAk4@xYmNj117l=nNJL45ua8x7ey(0(N`6wRUPW#JP&EUCO@$SZnVVXYs8Erc zlUHn2VXFjIVFhG^g!Ppaz)DK8ZIvQ?0~DO|i&7O#^-S~(l1A zfjnEKjFOT9D}DX)@^Za$W4-*MbbUihOG|wNBYh(yU7!lx;>x^|#0uTKVr7USFmqf| zi<65o3raHc^AtelCMM;Vme?vOfh>Xph&xL%(-1c06+^uR^q@XSM&D4+Kp$>4P^%3{ z)XKjoGZknv$b36P8?Z_gF{nK@`XI}Z90TzwSQO}0J1!f2c(B=V`5aP@1cs!wr;B5V zg<$fWul237Y?_bwwgoyAaoGI&=Q6GHdvw&j6)78&qol`;+07##gL;wH) literal 0 HcmV?d00001 From 02b67bb393ed475334dadf32266b6cb5f97dd89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=93=E5=89=91=E9=94=90?= Date: Thu, 17 Dec 2015 17:37:33 +0800 Subject: [PATCH 2/2] modify read --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index b9fe70b..02a316a 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,13 @@ Go ahead and experiment with these properties: @property (strong, nonatomic) UIColor *pageItemsTitleColor; @property (strong, nonatomic) UIColor *selectedPageItemColor; +modify by arrayinfree +--------------- + @property (strong, nonatomic) DAPagesContainerTopBar *topBar; + @property (strong, nonatomic) UIScrollView *scrollView; + +DaPagesConntainerTopBar.h +- (void)layoutItemWithSpecifyX:(float)offectX Y:(float)offectY w:(float)width h:(float)height; TODO ==============