Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion DAPagesContainer/DAPagesContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
//

#import <UIKit/UIKit.h>

#import "DAPagesContainerTopBar.h"
#import "DAPageIndicatorView.h"

@interface DAPagesContainer : UIViewController

Expand Down Expand Up @@ -83,4 +84,7 @@
*/
- (void)updateLayoutForNewOrientation:(UIInterfaceOrientation)orientation;


@property (strong, nonatomic) DAPagesContainerTopBar *topBar;
@property (strong, nonatomic) UIScrollView *scrollView;
@end
9 changes: 3 additions & 6 deletions DAPagesContainer/DAPagesContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@

#import "DAPagesContainer.h"

#import "DAPagesContainerTopBar.h"
#import "DAPageIndicatorView.h"



@interface DAPagesContainer () <DAPagesContainerTopBarDelegate, UIScrollViewDelegate>

@property (strong, nonatomic) DAPagesContainerTopBar *topBar;
@property (strong, nonatomic) UIScrollView *scrollView;
@property (weak, nonatomic) UIScrollView *observingScrollView;
@property (strong, nonatomic) UIView *pageIndicatorView;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions DAPagesContainer/DAPagesContainerTopBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 25 additions & 7 deletions DAPagesContainer/DAPagesContainerTopBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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];
Expand Down
4 changes: 4 additions & 0 deletions DAPagesContainerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -141,6 +143,7 @@
438BA8B6175786240033EB2D /* Images */ = {
isa = PBXGroup;
children = (
EFAB51CC1C22B4AE00F395B5 /* indicator.png */,
43222CBA1768E49F0088986F /* beaver.jpg */,
43222CBB1768E49F0088986F /* buckDeer.jpg */,
43222CBC1768E49F0088986F /* cat.jpg */,
Expand Down Expand Up @@ -206,6 +209,7 @@
43222CB81768E48E0088986F /* [email protected] 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 */,
Expand Down
5 changes: 5 additions & 0 deletions DAPagesContainerDemo/DAViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
==============
Expand Down
Binary file added indicator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.