From b59235d85ec4b41b49d461c3ea06be697413ed06 Mon Sep 17 00:00:00 2001 From: Valentin Strazdin <> Date: Wed, 2 Jun 2021 20:30:45 +0300 Subject: [PATCH] Add customizable itemScrollMenuViewWidth --- .../YSLContainerViewController.h | 1 + .../YSLContainerViewController.m | 1 + YSLContainerViewController/YSLScrollMenuView.h | 1 + YSLContainerViewController/YSLScrollMenuView.m | 17 +++++++++-------- 4 files changed, 12 insertions(+), 8 deletions(-) mode change 100644 => 100755 YSLContainerViewController/YSLContainerViewController.h mode change 100644 => 100755 YSLContainerViewController/YSLContainerViewController.m mode change 100644 => 100755 YSLContainerViewController/YSLScrollMenuView.h mode change 100644 => 100755 YSLContainerViewController/YSLScrollMenuView.m diff --git a/YSLContainerViewController/YSLContainerViewController.h b/YSLContainerViewController/YSLContainerViewController.h old mode 100644 new mode 100755 index 0b65c5f..9c1e76a --- a/YSLContainerViewController/YSLContainerViewController.h +++ b/YSLContainerViewController/YSLContainerViewController.h @@ -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 diff --git a/YSLContainerViewController/YSLContainerViewController.m b/YSLContainerViewController/YSLContainerViewController.m old mode 100644 new mode 100755 index d05cc78..64cbe56 --- a/YSLContainerViewController/YSLContainerViewController.m +++ b/YSLContainerViewController/YSLContainerViewController.m @@ -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]; diff --git a/YSLContainerViewController/YSLScrollMenuView.h b/YSLContainerViewController/YSLScrollMenuView.h old mode 100644 new mode 100755 index 5b77d83..c4d11f6 --- a/YSLContainerViewController/YSLScrollMenuView.h +++ b/YSLContainerViewController/YSLScrollMenuView.h @@ -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; diff --git a/YSLContainerViewController/YSLScrollMenuView.m b/YSLContainerViewController/YSLScrollMenuView.m old mode 100644 new mode 100755 index 759381e..aacf867 --- a/YSLContainerViewController/YSLScrollMenuView.m +++ b/YSLContainerViewController/YSLScrollMenuView.m @@ -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; @@ -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]; @@ -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; @@ -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]; } @@ -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); } @@ -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;