Segment+頁面滑動
Demo:
github: https://github.com/Luy7788/LySegmentMenu
重新修改了樣式:
舊版Demo:
github: https://github.com/Super-lying/LyScrollMenu
code4app下載地址: http://code4app.com/thread-9069-1-1.html
使用方法
/**
* 初始化方法1
* 在屏幕內(nèi)最多顯示的標(biāo)題個數(shù)默認為5個
*
* @param frame
* @param viewArr scrollView上要添加的view數(shù)組 -> @[VC1.view,VC2.view,VC3.view,VC4.view,VC5.view]
* @param titleArr 標(biāo)題數(shù)組 -> @[@"標(biāo)題1",@"標(biāo)題2",@"標(biāo)題3",@"標(biāo)題4",@"標(biāo)題5"],
*
*/
-(instancetype)initWithFrame:(CGRect)frame ControllerViewArray:(NSArray *)viewArr TitleArray:(NSArray *)titleArr;
/**
* 初始化方法2
* 可設(shè)置最多顯示的標(biāo)題個數(shù)
*
* @param frame
* @param viewArr scrollView上要添加的view數(shù)組 -> @[VC1.view,VC2.view,VC3.view,VC4.view,VC5.view]
* @param titleArr 標(biāo)題數(shù)組 -> @[@"標(biāo)題1",@"標(biāo)題2",@"標(biāo)題3",@"標(biāo)題4",@"標(biāo)題5"]
* @param maxNum 在屏幕內(nèi)最多顯示的標(biāo)題個數(shù)
*
*/
-(instancetype)initWithFrame:(CGRect)frame ControllerViewArray:(NSArray *)viewArr TitleArray:(NSArray *)titleArr MaxShowTitleNum:(NSInteger)maxNum;
/**
* 代理方法
*
* @param currentView 當(dāng)前的UIview
* @param index 當(dāng)前view的索引
*/
- (void)LyScrollMenuCurrentView:(UIView *)currentView didSelectItemWithIndex:(NSInteger)index;
簡單的例子:直接將多個view和標(biāo)題添加給LyScrollMenu:
UIViewController *VC1 = [[UIViewController alloc]init];
[VC1.view setBackgroundColor:[UIColor redColor]];
UIViewController *VC2 = [[UIViewController alloc]init];
[VC2.view setBackgroundColor:[UIColor blueColor]];
UIViewController *VC3 = [[UIViewController alloc]init];
[VC3.view setBackgroundColor:[UIColor grayColor]];
UIViewController *VC4 = [[UIViewController alloc]init];
[VC4.view setBackgroundColor:[UIColor greenColor]];
UIViewController *VC5 = [[UIViewController alloc]init];
[VC5.view setBackgroundColor:[UIColor purpleColor]];
UIViewController *VC6 = [[UIViewController alloc]init];
[VC6.view setBackgroundColor:[UIColor lightGrayColor]];
UIViewController *VC7 = [[UIViewController alloc]init];
[VC7.view setBackgroundColor:[UIColor yellowColor]];
CGRect Rect = CGRectMake(0, 20, kSCREEN_WIDTH, kSCREEN_HEIGHT);
LyScrollMenu *LyMenu = [[LyScrollMenu alloc]initWithFrame:Rect
ControllerViewArray:@[VC1.view,VC2.view,VC3.view,VC4.view,VC5.view,VC6.view,VC7.view]
TitleArray:@[@"標(biāo)題1",@"標(biāo)題2",@"標(biāo)題3",@"標(biāo)題4",@"標(biāo)題5",@"標(biāo)題6",@"標(biāo)題7"]
MaxShowTitleNum:5];
LyMenu.delegate = self;
[self.view addSubview:LyMenu];
實現(xiàn)的效果