Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initWithCode and init AXStretchableHeaderTabViewController's view… #1

Merged
merged 1 commit into from
Mar 1, 2017
Merged
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
3 changes: 3 additions & 0 deletions Classes/AXStretchableHeaderTabViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
@property (weak, nonatomic) IBOutlet UIScrollView *containerView;
@property (nonatomic) BOOL shouldBounceHeaderView;

// only call after view has appeared
- (void)switchToIndex:(NSUInteger)index;

// Layout
- (void)layoutHeaderViewAndTabBar;
- (void)layoutViewControllers;
Expand Down
50 changes: 36 additions & 14 deletions Classes/AXStretchableHeaderTabViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,48 @@ @implementation AXStretchableHeaderTabViewController {
CGFloat _headerViewTopConstraintConstant;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
// // MEMO:
// // An inherited class does not load xib file.
// // So, this code assigns class name of AXStretchableHeaderTabViewController clearly.
// self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
// if (self) {
//
// }
// return self;
//}

- (void)switchToIndex:(NSUInteger)index
{
// MEMO:
// An inherited class does not load xib file.
// So, this code assigns class name of AXStretchableHeaderTabViewController clearly.
self = [super initWithNibName:NSStringFromClass([AXStretchableHeaderTabViewController class]) bundle:nibBundleOrNil];
if (self) {
// Custom initialization
_shouldBounceHeaderView = YES;

_tabBar = [[AXTabBar alloc] init];
[_tabBar setDelegate:self];
}
return self;
if (self.viewControllers == nil
|| index >= self.viewControllers.count)
return;
self.tabBar.selectedItem = self.tabBar.items[index];
[self.containerView setContentOffset:(CGPoint) { index *CGRectGetWidth(
self.containerView
.bounds),
self.containerView
.contentOffset
.y } animated:YES];
self.selectedIndex = index;
}

- (void)viewDidLoad
{
[super viewDidLoad];


// Custom initialization
[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([AXStretchableHeaderTabViewController class]) owner:self options:nil];

_shouldBounceHeaderView = YES;

if (!_tabBar) {
_tabBar = [[AXTabBar alloc] init];
}

[_tabBar setDelegate:self];
[_tabBar sizeToFit];
[self.view addSubview:_tabBar];
}
Expand Down
20 changes: 17 additions & 3 deletions Classes/AXTabBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self commonInit];
}
return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self commonInit];
}
return self;
}

-(void)commonInit
{
_tabBarButtonFont = [UIFont systemFontOfSize:14.0];

_toolbar = [[UIToolbar alloc] init];
Expand All @@ -38,11 +54,9 @@ - (id)initWithFrame:(CGRect)frame
_bottomSeparator = [CALayer layer];
[_bottomSeparator setBackgroundColor:[[UIColor colorWithWhite:0.0 alpha:0.1] CGColor]];
[self.layer addSublayer:_bottomSeparator];

_indicatorLayer = [CALayer layer];
[self.layer addSublayer:_indicatorLayer];
}
return self;
}

- (void)layoutSubviews
Expand Down
18 changes: 16 additions & 2 deletions Classes/AXTabBarItemButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@ - (id)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self commonInit];
}
return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self commonInit];
}
return self;
}

-(void)commonInit
{
[self setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
[self setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
[self setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
}
return self;
}

- (void)layoutSubviews
Expand Down