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
1 change: 1 addition & 0 deletions YSLContainerViewController/YSLContainerViewController.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@property (nonatomic, strong) UIColor *menuItemSelectedTitleColor;
@property (nonatomic, strong) UIColor *menuBackGroudColor;
@property (nonatomic, strong) UIColor *menuIndicatorColor;
@property (nonatomic) CGFloat menuScrollMenuViewWidth;

- (id)initWithControllers:(NSArray *)controllers
topBarHeight:(CGFloat)topBarHeight
Expand Down
1 change: 1 addition & 0 deletions YSLContainerViewController/YSLContainerViewController.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ - (void)viewDidLoad {
_menuView.itemfont = self.menuItemFont;
_menuView.itemTitleColor = self.menuItemTitleColor;
_menuView.itemIndicatorColor = self.menuIndicatorColor;
_menuView.itemScrollMenuViewWidth = self.menuScrollMenuViewWidth;
_menuView.scrollView.scrollsToTop = NO;
[_menuView setItemTitleArray:self.titles];
[self.view addSubview:_menuView];
Expand Down
1 change: 1 addition & 0 deletions YSLContainerViewController/YSLScrollMenuView.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@property (nonatomic, strong) UIColor *itemTitleColor;
@property (nonatomic, strong) UIColor *itemSelectedTitleColor;
@property (nonatomic, strong) UIColor *itemIndicatorColor;
@property (nonatomic) CGFloat itemScrollMenuViewWidth;

- (void)setShadowView;

Expand Down
17 changes: 9 additions & 8 deletions YSLContainerViewController/YSLScrollMenuView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "YSLScrollMenuView.h"

static const CGFloat kYSLScrollMenuViewWidth = 90;
//static const CGFloat kYSLScrollMenuViewWidth = 90;
static const CGFloat kYSLScrollMenuViewMargin = 10;
static const CGFloat kYSLIndicatorHeight = 3;

Expand All @@ -27,6 +27,7 @@ - (id)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self) {
// default
_itemScrollMenuViewWidth = 90;
_viewbackgroudColor = [UIColor whiteColor];
_itemfont = [UIFont systemFontOfSize:16];
_itemTitleColor = [UIColor colorWithRed:0.866667 green:0.866667 blue:0.866667 alpha:1.0];
Expand Down Expand Up @@ -82,7 +83,7 @@ - (void)setItemTitleArray:(NSArray *)itemTitleArray
NSMutableArray *views = [NSMutableArray array];

for (int i = 0; i < itemTitleArray.count; i++) {
CGRect frame = CGRectMake(0, 0, kYSLScrollMenuViewWidth, CGRectGetHeight(self.frame));
CGRect frame = CGRectMake(0, 0, self.itemScrollMenuViewWidth, CGRectGetHeight(self.frame));
UILabel *itemView = [[UILabel alloc] initWithFrame:frame];
[self.scrollView addSubview:itemView];
itemView.tag = i;
Expand All @@ -102,7 +103,7 @@ - (void)setItemTitleArray:(NSArray *)itemTitleArray

// indicator
_indicatorView = [[UIView alloc]init];
_indicatorView.frame = CGRectMake(10, _scrollView.frame.size.height - kYSLIndicatorHeight, kYSLScrollMenuViewWidth, kYSLIndicatorHeight);
_indicatorView.frame = CGRectMake(10, _scrollView.frame.size.height - kYSLIndicatorHeight, self.itemScrollMenuViewWidth, kYSLIndicatorHeight);
_indicatorView.backgroundColor = self.itemIndicatorColor;
[_scrollView addSubview:_indicatorView];
}
Expand All @@ -114,15 +115,15 @@ - (void)setIndicatorViewFrameWithRatio:(CGFloat)ratio isNextItem:(BOOL)isNextIte
{
CGFloat indicatorX = 0.0;
if (isNextItem) {
indicatorX = ((kYSLScrollMenuViewMargin + kYSLScrollMenuViewWidth) * ratio ) + (toIndex * kYSLScrollMenuViewWidth) + ((toIndex + 1) * kYSLScrollMenuViewMargin);
indicatorX = ((kYSLScrollMenuViewMargin + self.itemScrollMenuViewWidth) * ratio ) + (toIndex * self.itemScrollMenuViewWidth) + ((toIndex + 1) * kYSLScrollMenuViewMargin);
} else {
indicatorX = ((kYSLScrollMenuViewMargin + kYSLScrollMenuViewWidth) * (1 - ratio) ) + (toIndex * kYSLScrollMenuViewWidth) + ((toIndex + 1) * kYSLScrollMenuViewMargin);
indicatorX = ((kYSLScrollMenuViewMargin + self.itemScrollMenuViewWidth) * (1 - ratio) ) + (toIndex * self.itemScrollMenuViewWidth) + ((toIndex + 1) * kYSLScrollMenuViewMargin);
}

if (indicatorX < kYSLScrollMenuViewMargin || indicatorX > self.scrollView.contentSize.width - (kYSLScrollMenuViewMargin + kYSLScrollMenuViewWidth)) {
if (indicatorX < kYSLScrollMenuViewMargin || indicatorX > self.scrollView.contentSize.width - (kYSLScrollMenuViewMargin + self.itemScrollMenuViewWidth)) {
return;
}
_indicatorView.frame = CGRectMake(indicatorX, _scrollView.frame.size.height - kYSLIndicatorHeight, kYSLScrollMenuViewWidth, kYSLIndicatorHeight);
_indicatorView.frame = CGRectMake(indicatorX, _scrollView.frame.size.height - kYSLIndicatorHeight, self.itemScrollMenuViewWidth, kYSLIndicatorHeight);
// NSLog(@"retio : %f",_indicatorView.frame.origin.x);
}

Expand Down Expand Up @@ -168,7 +169,7 @@ - (void)layoutSubviews

CGFloat x = kYSLScrollMenuViewMargin;
for (NSUInteger i = 0; i < self.itemViewArray.count; i++) {
CGFloat width = kYSLScrollMenuViewWidth;
CGFloat width = self.itemScrollMenuViewWidth;
UIView *itemView = self.itemViewArray[i];
itemView.frame = CGRectMake(x, 0, width, self.scrollView.frame.size.height);
x += width + kYSLScrollMenuViewMargin;
Expand Down